From 2245ba7abe51d4a90a8ef6c9a9754c1bad4e0dd3 Mon Sep 17 00:00:00 2001 From: Alex Hoyau Date: Fri, 29 Sep 2023 17:04:14 +0300 Subject: [PATCH] fix image upload with gitlab api --- README.md | 6 ++++++ src/ts/plugins/server/GitlabConnector.ts | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 90066f647..7eb56144e 100755 --- a/README.md +++ b/README.md @@ -78,6 +78,12 @@ Then, you can run Silex with the `silex` command. The entry point is `src/ts/ser You can configure Silex using environment variables and command-line options. All available options can be found in `src/ts/server/cli.ts`. +There are config files (same as plugins) in the `examples/` folder. To start Silex locally with these config: + +```sh +$ SILEX_CLIENT_CONFIG=./examples/client-config-transformers.js SILEX_CONFIG=`pwd`/examples/server-config-plugins.js npm run start:debug +``` + ## Contributing Contributions are welcome! Please read our [contributing guidelines](CONTRIBUTING.md) for details on how to contribute to Silex. diff --git a/src/ts/plugins/server/GitlabConnector.ts b/src/ts/plugins/server/GitlabConnector.ts index 3c40c1af7..a68c8e85e 100644 --- a/src/ts/plugins/server/GitlabConnector.ts +++ b/src/ts/plugins/server/GitlabConnector.ts @@ -293,7 +293,9 @@ export default class GitlabConnector implements StorageConnector { // Handle the case when the server returns an non-JSON response (e.g. 400 Bad Request) const text = await response.text() if(!response.ok) { - if (response.status === 401 && session?.gitlab?.token?.refresh_token) { + if (text.includes('A file with this name doesn\'t exist')) { + throw new ApiError('Gitlab API error (5): Not Found', 404) + } else if (response.status === 401 && session?.gitlab?.token?.refresh_token) { // Refresh the token const token = session?.gitlab?.token const body = { @@ -327,7 +329,6 @@ export default class GitlabConnector implements StorageConnector { } } else { const message = typeof json?.message === 'object' ? Object.entries(json.message).map(entry => entry.join(' ')).join(' ') : json?.message ?? json?.error ?? response.statusText - console.error('Gitlab API error (1)', response.status, response.statusText, {message}) throw new ApiError(`Gitlab API error (1): ${message}`, response.status) } } @@ -520,7 +521,6 @@ export default class GitlabConnector implements StorageConnector { branch: this.options.branch, commit_message: 'Update website data from Silex', content: JSON.stringify(websiteData), - file_path: WEBSITE_DATA_FILE, id: websiteId, }) } @@ -648,12 +648,14 @@ export default class GitlabConnector implements StorageConnector { for (const file of files) { // Convert to base64 const content = (await contentToBuffer(file.content)).toString('base64') + const path = this.getAssetPath(file.path) + try { - await this.updateFile(session, websiteId, this.getAssetPath(file.path), content, true) + await this.updateFile(session, websiteId, path, content, true) } catch (e) { // If the file does not exist, create it if (e.statusCode === 404 || e.httpStatusCode === 404 || e.message.endsWith('A file with this name doesn\'t exist')) { - await this.createFile(session, websiteId, this.getAssetPath(file.path), content, true) + await this.createFile(session, websiteId, path, content, true) } else { throw e }