KV存储改为默认开启

保存

保存
This commit is contained in:
eoao
2025-12-31 23:33:52 +08:00
parent 69632c8cc6
commit 88a4b9dff5
16 changed files with 75 additions and 80 deletions

View File

@@ -82,17 +82,28 @@ const attService = {
}
//邮件正文站内图片转cid附件
if (src && src.startsWith(domainUtils.toOssDomain(r2Domain))) {
if (src && (src.startsWith(domainUtils.toOssDomain(r2Domain)) || src.startsWith('attachments/'))) {
const cid = uuidv4().replace(/-/g, '')
img.setAttribute('src', 'cid:' + cid);
const attData = {};
attData.key = src.replace(domainUtils.toOssDomain(r2Domain) + '/','');
attData.path = src;
if (src.startsWith(domainUtils.toOssDomain(r2Domain))) {
attData.key = src.replace(domainUtils.toOssDomain(r2Domain) + '/','');
attData.path = src;
}
if (src.startsWith('attachments/')) {
const origin = new URL(c.req.url).origin;
attData.key = src;
attData.path = origin + '/' + src;
}
attData.contentId = cid;
attData.type = attConst.type.EMBED;
imageDataList.push(attData);
}
const hasInlineWidth = img.hasAttribute('width');

View File

@@ -197,23 +197,6 @@ const emailService = {
}
if (imageDataList.length > 0 && !r2Domain) {
throw new BizError(t('noOsDomainSendPic'));
}
if (imageDataList.length > 0 && !await r2Service.hasOSS(c)) {
throw new BizError(t('noOsSendPic'));
}
if (attachments.length > 0 && !r2Domain) {
throw new BizError(t('noOsDomainSendAtt'));
}
if (attachments.length > 0 && !await r2Service.hasOSS(c)) {
throw new BizError(t('noOsSendAtt'));
}
if (attachments.length > 0 && manyType === 'divide') {
throw new BizError(t('noSeparateSend'));
}
@@ -385,7 +368,7 @@ const emailService = {
await attService.saveArticleAtt(c, imageDataList, userId, accountId, emailRow.emailId);
}
if (attachments?.length > 0 && await r2Service.hasOSS(c)) {
if (attachments?.length > 0) {
await attService.saveSendAtt(c, attachments, userId, accountId, emailRow.emailId);
}

View File

@@ -230,7 +230,7 @@ const loginService = {
let authInfo = await c.env.kv.get(KvConst.AUTH_INFO + userRow.userId, { type: 'json' });
if (authInfo) {
if (authInfo && (authInfo.user.email === userRow.email)) {
if (authInfo.tokens.length > 10) {
authInfo.tokens.shift();

View File

@@ -5,20 +5,20 @@ import { settingConst } from '../const/entity-const';
const r2Service = {
async hasOSS(c) {
async storageType(c) {
const setting = await settingService.query(c);
const { kvStorage, bucket, endpoint, s3AccessKey, s3SecretKey } = setting;
const { bucket, endpoint, s3AccessKey, s3SecretKey } = setting;
if (kvStorage === settingConst.kvStorage.OPEN) {
return true;
if (!!(bucket && endpoint && s3AccessKey && s3SecretKey)) {
return 'S3';
}
if (c.env.r2) {
return true;
return 'R2';
}
return !!(bucket && endpoint && s3AccessKey && s3SecretKey);
return 'KV';
},
async putObj(c, key, content, metadata) {

View File

@@ -1,12 +1,12 @@
import KvConst from '../const/kv-const';
import setting from '../entity/setting';
import orm from '../entity/orm';
import { verifyRecordType } from '../const/entity-const';
import {verifyRecordType} from '../const/entity-const';
import fileUtils from '../utils/file-utils';
import r2Service from './r2-service';
import constant from '../const/constant';
import BizError from '../error/biz-error';
import { t } from '../i18n/i18n'
import {t} from '../i18n/i18n'
import verifyRecordService from './verify-record-service';
const settingService = {
@@ -101,6 +101,8 @@ const settingService = {
settingRow.regVerifyOpen = regVerifyOpen
settingRow.addVerifyOpen = addVerifyOpen
settingRow.storageType = await r2Service.storageType(c);
return settingRow;
},
@@ -131,37 +133,21 @@ const settingService = {
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)
}
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)) {
throw new BizError(t('noOsUpBack'));
}
if (!settingRow.r2Domain) {
throw new BizError(t('noOsDomainUpBack'));
}
const file = fileUtils.base64ToFile(background)
const arrayBuffer = await file.arrayBuffer();
@@ -183,7 +169,7 @@ const settingService = {
async websiteConfig(c) {
const settingRow = await this.get(c, true)
const settingRow = await this.get(c, true);
return {
register: settingRow.register,

View File

@@ -25,6 +25,10 @@ const userService = {
const userRow = await userService.selectById(c, userId);
if (!userRow) {
throw new BizError(t('authExpired'), 401);
}
const [account, roleRow, permKeys] = await Promise.all([
accountService.selectByEmailIncludeDel(c, userRow.email),
roleService.selectById(c, userRow.type),