Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
feat: Implement s3redirect mode
Browse files Browse the repository at this point in the history
This option will redirect the user to the S3 resource, rather than proxying the file through ass. Reference #108
  • Loading branch information
tycrek committed Oct 14, 2022
1 parent dc27e80 commit 8c89208
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/routers/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Request, Response } from 'express';
import { deleteS3 } from '../storage';
import { SkynetDelete, SkynetDownload } from '../skynet';
import { path, log, getTrueHttp, getTrueDomain, formatBytes, formatTimestamp, getS3url, getDirectUrl, getResourceColor, replaceholder } from '../utils';
const { diskFilePath, s3enabled, viewDirect, useSia }: Config = fs.readJsonSync(path('config.json'));
const { diskFilePath, s3enabled, s3redirect, viewDirect, useSia }: Config = fs.readJsonSync(path('config.json'));
const { CODE_UNAUTHORIZED, CODE_NOT_FOUND, }: MagicNumbers = fs.readJsonSync(path('MagicNumbers.json'));
import { data } from '../data';
import { users } from '../auth';
Expand Down Expand Up @@ -79,6 +79,7 @@ router.get('/direct*', (req: Request, res: Response, next) => data().get(req.ass
file.headers.forEach((value, header) => res.setHeader(header, value));
file.body?.pipe(res);
}),
s3redirect: () => res.redirect(getS3url(fileData.randomId, fileData.ext)),
sia: () => SkynetDownload(fileData)
.then((stream) => stream.pipe(res))
.then(() => SkynetDelete(fileData)),
Expand All @@ -91,7 +92,7 @@ router.get('/direct*', (req: Request, res: Response, next) => data().get(req.ass
.sendFile(path(fileData.path), (err) => err ? reject(err) : resolve(void 0))))
};

return uploaders[fileData.randomId.startsWith('sia://') ? 'sia' : s3enabled ? 's3' : 'local']();
return uploaders[fileData.randomId.startsWith('sia://') ? 'sia' : s3enabled ? (s3redirect ? 's3redirect' : 's3') : 'local']();
}).catch(next));

// Thumbnail response
Expand Down

0 comments on commit 8c89208

Please sign in to comment.