新增KV数据库存储附件

This commit is contained in:
eoao
2025-10-21 20:45:20 +08:00
parent dad4a22356
commit fdf9e95d67
18 changed files with 213 additions and 73 deletions

View File

@@ -1,12 +1,9 @@
import KvConst from '../const/kv-const';
import setting from '../entity/setting';
import orm from '../entity/orm';
import { settingConst, verifyRecordType } from '../const/entity-const';
import { verifyRecordType } from '../const/entity-const';
import fileUtils from '../utils/file-utils';
import r2Service from './r2-service';
import emailService from './email-service';
import accountService from './account-service';
import userService from './user-service';
import constant from '../const/constant';
import BizError from '../error/biz-error';
import { t } from '../i18n/i18n'
@@ -100,12 +97,38 @@ const settingService = {
await this.refresh(c);
},
async deleteBackground(c) {
const { background } = await this.query(c);
if (!background) return
if (background.startsWith('http')) {
await orm(c).update(setting).set({ background: '' }).run();
await this.refresh(c)
return;
}
const hasOss = await r2Service.hasOSS(c);
if (hasOss) {
if (background) {
await r2Service.delete(c,background)
await orm(c).update(setting).set({ background: '' }).run();
await this.refresh(c)
}
}
},
async setBackground(c, params) {
const settingRow = await this.query(c);
let { background } = params
await this.deleteBackground(c);
if (background && !background.startsWith('http')) {
if (!await r2Service.hasOSS(c)) {
@@ -130,14 +153,6 @@ const settingService = {
}
if (settingRow.background) {
try {
await r2Service.delete(c, settingRow.background);
} catch (e) {
console.error(e)
}
}
await orm(c).update(setting).set({ background }).run();
await this.refresh(c);
return background;