fix(org): validate compress URL; register org_homepage in hty_resources

Made-with: Cursor
This commit is contained in:
2026-04-28 08:25:09 +08:00
parent 6d74a34aa2
commit 1509bcbb99
2 changed files with 20 additions and 4 deletions
+8 -1
View File
@@ -2,7 +2,7 @@
<div class="main">
<van-cell-group inset>
<div class="editor-toolbar">
<span class="toolbar-hint">图片与头像相同经压缩任务处理</span>
<span class="toolbar-hint">图片经服务端压缩后上传并记入资源库便于排查</span>
<van-uploader
:max-count="1"
:max-size="orgHomepageImageMaxBytes"
@@ -128,6 +128,13 @@ export default defineComponent({
const urlRaw = await ImageHelper.compress_by_form(file);
if (!urlRaw) return;
const url = urlRaw.split("?")[0];
const rid = await ImageHelper.create_resource(url, file.name || "image.jpg", {
res_type: "org_homepage",
});
if (!rid) {
showFailToast("资源登记失败,图片可能已上传但未绑定账号");
return;
}
await insertMarkdownAtCaret(`\n![](${url})\n`);
showSuccessToast("已插入图片");
} finally {
+12 -3
View File
@@ -129,7 +129,12 @@ const ImageHelper = {
headers: {'Content-Type': 'multipart/form-data'},
})
if (r) {
return d;
const raw = typeof d === 'string' ? d.trim() : '';
if (raw && /^https?:\/\//i.test(raw) && !/\s/.test(raw)) {
return raw;
}
showFailToast('图片上传返回异常,请重试');
return undefined;
}
showFailToast(e);
},
@@ -165,10 +170,14 @@ const ImageHelper = {
image.src = src;
})
},
create_resource: async (url: string, filename?: string) => {
create_resource: async (
url: string,
filename?: string,
extra?: { res_type?: string },
) => {
const {r, d, e} = await request({
url: '/api/v1/uc/create_hty_resource', method: 'POST',
data: { filename, url }
data: { filename, url, ...extra }
});
if(r) {
return d