core&ui: goodbye, minio (#417)

This commit is contained in:
undefined authored and GitHub committed 2022-08-23 00:40:21 +08:00
1 parent 7abc0a7d1b
commit e06c86e9dd
34 files changed
+410 -322

No files matched your search

+22
View File
@@ -1,9 +1,11 @@
/* eslint-disable camelcase */
import { statSync } from 'fs';
import { pick } from 'lodash';
import { lookup } from 'mime-types';
import {
BadRequestError, ForbiddenError, ValidationError,
} from '../error';
import { md5 } from '../lib/crypto';
import { PRIV } from '../model/builtin';
import * as oplog from '../model/oplog';
import storage from '../model/storage';
@@ -12,6 +14,8 @@ import user from '../model/user';
import {
Handler, param, post, Route, Types,
} from '../service/server';
import { encodeRFC5987ValueChars } from '../service/storage';
import { builtinConfig } from '../settings';
import { sortFiles } from '../utils';
class SwitchLanguageHandler extends Handler {
@@ -101,6 +105,23 @@ export class FSDownloadHandler extends Handler {
}
}
export class StorageHandler extends Handler {
@param('target', Types.Name)
@param('filename', Types.Name, true)
@param('expire', Types.UnsignedInt)
@param('secret', Types.String)
async get(domainId: string, target: string, filename = '', expire: number, secret: string) {
const expected = md5(`${target}/${expire}/${builtinConfig.file.secret}`);
if (expire < Date.now()) throw new ForbiddenError('Link expired');
if (secret !== expected) throw new ForbiddenError('Invalid secret');
this.response.body = await storage.get(target);
this.response.type = (target.endsWith('.out') || target.endsWith('.ans'))
? 'text/plain'
: lookup(target) || 'application/octet-stream';
if (filename) this.response.disposition = `attachment; filename="${encodeRFC5987ValueChars(filename)}"`;
}
}
export class SwitchAccountHandler extends Handler {
@param('uid', Types.Int)
async get(domainId: string, uid: number) {
@@ -113,6 +134,7 @@ export async function apply() {
Route('switch_language', '/language/:lang', SwitchLanguageHandler);
Route('home_files', '/file', FilesHandler);
Route('fs_download', '/file/:uid/:filename', FSDownloadHandler);
Route('storage', '/storage', StorageHandler);
Route('switch_account', '/account', SwitchAccountHandler, PRIV.PRIV_EDIT_SYSTEM);
}