Skip to content

Commit

Permalink
fix: purge missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Apr 10, 2023
1 parent ae3b734 commit e20c29d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/routes/download/u/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import RequireAuthentication from '../../../middleware/RequireAuthentication';
import DB from '../../../lib/storage/db';
import StorageHandler from '../../../lib/storage/StorageHandler';
import { sendError } from '../../../lib/error/sendError';
import { AWSError } from 'aws-sdk';

const router = express.Router();

Expand All @@ -27,6 +28,10 @@ router.get('/u/:key', RequireAuthentication, async (req, res) => {
} catch (error) {
console.error(error);
console.info('unknown error');
if ((error as AWSError).name.match(/NoSuchKey/)) {
await DB('uploads').where(query).delete();
return res.redirect('/uploads');
}
res.status(404).send();
sendError(error);
}
Expand Down

0 comments on commit e20c29d

Please sign in to comment.