From 22a174c7e1edcb646ece6a452a48a0740cffc196 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sat, 26 Mar 2022 14:42:36 +0200 Subject: [PATCH] compatible with sharex custom uploader --- server/src/client/ClipIndex.js | 2 +- server/src/client/ServerClient.js | 1 + server/src/client/endpoints/api/Upload.js | 9 ++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/src/client/ClipIndex.js b/server/src/client/ClipIndex.js index a44a852..25ebf4d 100644 --- a/server/src/client/ClipIndex.js +++ b/server/src/client/ClipIndex.js @@ -66,7 +66,7 @@ class ClipIndex extends EventEmitter { fs.writeFileSync(this.indexDir, JSON.stringify(this.index)); this.emit('upload', this.index[filename]); - resolve(); + resolve(this.index[filename]); }); diff --git a/server/src/client/ServerClient.js b/server/src/client/ServerClient.js index c4845e3..accf3e3 100644 --- a/server/src/client/ServerClient.js +++ b/server/src/client/ServerClient.js @@ -40,6 +40,7 @@ class Client extends EventEmitter { this.port = parseInt(env.HTTP_PORT) + this.shardId; this.domain = env.NODE_ENV === 'production' ? env.DOMAIN : `localhost`; this.proto = env.NODE_ENV === 'production' ? 'https' : 'http'; + this.baseUrl = `${this.proto}://${this.domain}`; this.baseDirectory = path.resolve(__dirname, '../..'); this.mediaDirectory = path.join(this.baseDirectory, opts.media.videos); diff --git a/server/src/client/endpoints/api/Upload.js b/server/src/client/endpoints/api/Upload.js index 428a2fa..bd8b813 100644 --- a/server/src/client/endpoints/api/Upload.js +++ b/server/src/client/endpoints/api/Upload.js @@ -37,10 +37,13 @@ class Login extends APIEndpoint { this.logger.info(`${req.user.username}#${req.user.discriminator} is uploading ${name}`); try { - await this.client.clipIndex.add(file, name, req.user); - res.status(200).end(); + const result = await this.client.clipIndex.add(file, name, req.user); + res.status(200).json({ + url: `${this.client.baseUrl}/media/${name}`, + thumbnail: `${this.client.baseUrl}/thumbnails/${result.thumbnail}` + }); } catch (_) { - res.status(500).end(); + res.status(500).send('Internal error'); } }