mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 17:46:28 +08:00
core: fix builtin storage service
This commit is contained in:
3 files changed
+39
-28
No files matched your search
@@ -262,6 +262,10 @@ class RemoteStorageService {
|
||||
return url;
|
||||
}
|
||||
|
||||
async isLinkValid(_: string) {
|
||||
return false;
|
||||
}
|
||||
|
||||
async signUpload(target: string, size: number) {
|
||||
const client = this.alternatives.user || this.client;
|
||||
const { url, fields } = await createPresignedPost(client, {
|
||||
@@ -365,6 +369,12 @@ class LocalStorageService {
|
||||
return `/${url.toString().split('localhost/')[1]}`;
|
||||
}
|
||||
|
||||
async isLinkValid(link: string) {
|
||||
const [target, expire, secret] = link.split('/');
|
||||
const expected = md5(`${target}/${expire}/${this.config.secret}`);
|
||||
return expected === secret;
|
||||
}
|
||||
|
||||
async signUpload() {
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
@@ -416,6 +426,12 @@ export async function apply(ctx: Context, config: ReturnType<typeof FileSetting>
|
||||
ctx.set('storage', service);
|
||||
}
|
||||
|
||||
declare module '../context' {
|
||||
interface Context {
|
||||
storage: RemoteStorageService | LocalStorageService;
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated use ctx.storage instead */
|
||||
const serviceProxy = new Proxy({}, {
|
||||
get(self, key) {
|
||||
|
||||
Reference in new issue
Block a user