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

@@ -152,13 +152,7 @@ export async function email(message, env, ctx) {
attachment.accountId = emailRow.accountId;
});
try {
if (attachments.length > 0 && await r2Service.hasOSS({ env })) {
await attService.addAtt({ env }, attachments);
}
} catch (e) {
console.error(e);
}
await attService.addAtt({ env }, attachments);
emailRow = await emailService.completeReceive({ env }, account ? emailConst.status.RECEIVE : emailConst.status.NOONE, emailRow.emailId);

View File

@@ -11,7 +11,6 @@ const en = {
delMyAccount: 'Cannot delete your own account',
noUserAccount: 'This email does not belong to the current user',
usernameLengthLimit: 'Username length exceeds the limit',
noOsDomainSendPic: 'Cannot send body images: object storage domain not configured',
noOsSendPic: 'Cannot send body images: object storage not configured',
noOsDomainSendAtt: 'Cannot send attachments: object storage domain not configured',
noOsSendAtt: 'Cannot send attachments: object storage not configured',

View File

@@ -11,7 +11,6 @@ const zh = {
delMyAccount: '不可以删除自己的邮箱',
noUserAccount: '该邮箱不属于当前用户',
usernameLengthLimit: '用户名长度超出限制',
noOsDomainSendPic: '对象存储域名未配置不能发送正文图片',
noOsSendPic: '对象存储未配置不能发送正文图片',
noOsDomainSendAtt: '对象存储域名未配置不能发送附件',
noOsSendAtt: '对象存储未配置不能发送附件',

View File

@@ -30,6 +30,14 @@ const init = {
return c.text(t('initSuccess'));
},
async v2_7DB(c) {
try {
await c.env.db.prepare(`ALTER TABLE account ADD COLUMN all_receive INTEGER NOT NULL DEFAULT 0;`).run();
} catch (e) {
console.error(e)
}
},
async v2_6DB(c) {
try {
await c.env.db.prepare(`ALTER TABLE account ADD COLUMN all_receive INTEGER NOT NULL DEFAULT 0;`).run();
@@ -90,7 +98,6 @@ const init = {
try {
await c.env.db.batch([
c.env.db.prepare(`ALTER TABLE setting ADD COLUMN force_path_style INTEGER NOT NULL DEFAULT 1;`),
c.env.db.prepare(`ALTER TABLE setting ADD COLUMN kv_storage INTEGER NOT NULL DEFAULT 1;`),
c.env.db.prepare(`ALTER TABLE setting ADD COLUMN custom_domain TEXT NOT NULL DEFAULT '';`),
c.env.db.prepare(`ALTER TABLE setting ADD COLUMN tg_msg_to TEXT NOT NULL DEFAULT 'show';`),
c.env.db.prepare(`ALTER TABLE setting ADD COLUMN tg_msg_from TEXT NOT NULL DEFAULT 'only-name';`)

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),