fix bugs in contrib system, remove health endpoint
This commit is contained in:
@@ -432,66 +432,4 @@ This contribution contains the raw tool data for manual review and integration.`
|
||||
---
|
||||
*This contribution was submitted via the CC24-Hub web interface and contains only the raw tool data for manual integration.*`;
|
||||
}
|
||||
|
||||
async checkHealth(): Promise<{healthy: boolean, issues?: string[]}> {
|
||||
const issues: string[] = [];
|
||||
|
||||
try {
|
||||
// Check if local repo exists and is accessible
|
||||
try {
|
||||
await fs.access(this.config.localRepoPath);
|
||||
} catch {
|
||||
issues.push('Local repository path not accessible');
|
||||
}
|
||||
|
||||
// Check git status
|
||||
try {
|
||||
execSync('git status', { cwd: this.config.localRepoPath, stdio: 'pipe' });
|
||||
} catch {
|
||||
issues.push('Local repository is not a valid git repository');
|
||||
}
|
||||
|
||||
// Test API connectivity
|
||||
try {
|
||||
let testUrl: string;
|
||||
switch (this.config.provider) {
|
||||
case 'gitea':
|
||||
testUrl = `${this.config.apiEndpoint}/repos/${this.config.repoOwner}/${this.config.repoName}`;
|
||||
break;
|
||||
case 'github':
|
||||
testUrl = `${this.config.apiEndpoint}/repos/${this.config.repoOwner}/${this.config.repoName}`;
|
||||
break;
|
||||
case 'gitlab':
|
||||
testUrl = `${this.config.apiEndpoint}/projects/${encodeURIComponent(this.config.repoOwner + '/' + this.config.repoName)}`;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown provider');
|
||||
}
|
||||
|
||||
const response = await fetch(testUrl, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.config.apiToken}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
issues.push(`API connectivity failed: ${response.status}`);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
issues.push(`API test failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
}
|
||||
|
||||
return {
|
||||
healthy: issues.length === 0,
|
||||
issues: issues.length > 0 ? issues : undefined
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
return {
|
||||
healthy: false,
|
||||
issues: [`Health check failed: ${error instanceof Error ? error.message : 'Unknown error'}`]
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,6 +168,10 @@ export class NextcloudUploader {
|
||||
const categoryPath = this.sanitizeFilename(category);
|
||||
const remotePath = `${this.config.uploadPath}/${categoryPath}/${uniqueFilename}`;
|
||||
|
||||
// **FIX: Ensure directory exists before upload**
|
||||
const dirPath = `${this.config.uploadPath}/${categoryPath}`;
|
||||
await this.ensureDirectoryExists(dirPath);
|
||||
|
||||
// Convert file to buffer
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
@@ -207,6 +211,36 @@ export class NextcloudUploader {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private async ensureDirectoryExists(dirPath: string): Promise<void> {
|
||||
try {
|
||||
// Split path and create each directory level
|
||||
const parts = dirPath.split('/').filter(part => part);
|
||||
let currentPath = '';
|
||||
|
||||
for (const part of parts) {
|
||||
currentPath += '/' + part;
|
||||
|
||||
const mkcolUrl = `${this.config.endpoint}/remote.php/dav/files/${this.config.username}${currentPath}`;
|
||||
|
||||
const response = await fetch(mkcolUrl, {
|
||||
method: 'MKCOL',
|
||||
headers: {
|
||||
'Authorization': `Basic ${Buffer.from(`${this.config.username}:${this.config.password}`).toString('base64')}`
|
||||
}
|
||||
});
|
||||
|
||||
// 201 = created, 405 = already exists, both are fine
|
||||
if (response.status !== 201 && response.status !== 405) {
|
||||
console.warn(`Directory creation failed: ${response.status} for ${currentPath}`);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Failed to ensure directory exists:', error);
|
||||
// Don't fail upload for directory creation issues
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a public share link for the uploaded file
|
||||
|
||||
Reference in New Issue
Block a user