mirror of
https://github.com/laosb/ghos3.git
synced 2025-04-30 07:31:08 +00:00
fix: return error based on official approach.
This commit is contained in:
parent
06890b99cc
commit
91a3a1423c
3 changed files with 1190 additions and 4 deletions
|
@ -12,6 +12,8 @@
|
|||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.540.0",
|
||||
"@tryghost/errors": "^1.3.6",
|
||||
"@tryghost/tpl": "^0.1.33",
|
||||
"ghost-storage-base": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
1178
pnpm-lock.yaml
generated
1178
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
14
src/index.ts
14
src/index.ts
|
@ -5,6 +5,8 @@ import {
|
|||
S3,
|
||||
} from '@aws-sdk/client-s3'
|
||||
import StorageBase, { type ReadOptions, type Image } from 'ghost-storage-base'
|
||||
import errors from '@tryghost/errors'
|
||||
import tpl from '@tryghost/tpl'
|
||||
import { join } from 'path'
|
||||
import { createReadStream } from 'fs'
|
||||
import type { Readable } from 'stream'
|
||||
|
@ -197,16 +199,20 @@ class S3Storage extends StorageBase {
|
|||
stream.pipe(res)
|
||||
} catch (err) {
|
||||
if (err.name === 'NoSuchKey') {
|
||||
res.status(404).send('Image not found');
|
||||
return next(
|
||||
new errors.NotFoundError({
|
||||
message: tpl('File not found'),
|
||||
code: 'STATIC_FILE_NOT_FOUND',
|
||||
property: err.path,
|
||||
})
|
||||
)
|
||||
} else {
|
||||
res.status(500);
|
||||
next(err);
|
||||
next(new errors.InternalServerError({ err: err }))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async read(options: ReadOptions = { path: '' }) {
|
||||
let path = (options.path || '').replace(/\/$|\\$/, '')
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue