Update storage.js via upload script - 2026-11-04 10:00:01
This commit is contained in:
parent
ac4714ed07
commit
c3c5c86df9
|
|
@ -77,8 +77,9 @@ async function pump(key) {
|
||||||
|
|
||||||
// 还没存上的修改:正在发送 / 排队中的键,以及最近一次保存失败的键(保存成功后自动清掉)
|
// 还没存上的修改:正在发送 / 排队中的键,以及最近一次保存失败的键(保存成功后自动清掉)
|
||||||
const failed = {};
|
const failed = {};
|
||||||
|
let uploadsInFlight = 0; // 正在上传的文件(图片、附件)
|
||||||
export function hasUnsavedChanges() {
|
export function hasUnsavedChanges() {
|
||||||
return Object.values(saveState).some((st) => st.running || st.next) || Object.keys(failed).length > 0;
|
return uploadsInFlight > 0 || Object.values(saveState).some((st) => st.running || st.next) || Object.keys(failed).length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function storageSet(key, value) {
|
export function storageSet(key, value) {
|
||||||
|
|
@ -92,6 +93,10 @@ export function storageSet(key, value) {
|
||||||
|
|
||||||
// 上传一个与客户相关的沟通附件(文件本身存到磁盘,元数据由调用方存进客户记录)
|
// 上传一个与客户相关的沟通附件(文件本身存到磁盘,元数据由调用方存进客户记录)
|
||||||
export async function uploadFile(customerId, file) {
|
export async function uploadFile(customerId, file) {
|
||||||
|
uploadsInFlight++;
|
||||||
|
try { return await uploadFileNow(customerId, file); } finally { uploadsInFlight--; }
|
||||||
|
}
|
||||||
|
async function uploadFileNow(customerId, file) {
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('file', file);
|
fd.append('file', file);
|
||||||
const res = await fetch(`/api/uploads/${encodeURIComponent(customerId)}`, {
|
const res = await fetch(`/api/uploads/${encodeURIComponent(customerId)}`, {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue