sa2kit 1.6.52 → 1.6.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AliyunOSSProvider-KSYW2IOG.js +15 -0
- package/dist/{AliyunOSSProvider-2FARPAQD.js.map → AliyunOSSProvider-KSYW2IOG.js.map} +1 -1
- package/dist/AliyunOSSProvider-TBK3G7YK.mjs +6 -0
- package/dist/{AliyunOSSProvider-UMVGVBDJ.mjs.map → AliyunOSSProvider-TBK3G7YK.mjs.map} +1 -1
- package/dist/LocalStorageProvider-2DGYRQAB.mjs +6 -0
- package/dist/{LocalStorageProvider-PYOHETJV.mjs.map → LocalStorageProvider-2DGYRQAB.mjs.map} +1 -1
- package/dist/LocalStorageProvider-SSRW3ZJW.js +15 -0
- package/dist/{LocalStorageProvider-JQF5WK5H.js.map → LocalStorageProvider-SSRW3ZJW.js.map} +1 -1
- package/dist/UniversalFileService-336GFY6N.mjs +6 -0
- package/dist/{UniversalFileService-TNYKO6JN.mjs.map → UniversalFileService-336GFY6N.mjs.map} +1 -1
- package/dist/UniversalFileService-J6ET6KZK.js +15 -0
- package/dist/{UniversalFileService-RBV6EN5J.js.map → UniversalFileService-J6ET6KZK.js.map} +1 -1
- package/dist/booking-BXtkG2ns.d.mts +386 -0
- package/dist/booking-BXtkG2ns.d.ts +386 -0
- package/dist/bookingAdminService-B2QDjSHJ.d.ts +193 -0
- package/dist/bookingAdminService-Dmg7dC6V.d.mts +193 -0
- package/dist/calendar/index.js +11 -11
- package/dist/calendar/index.mjs +4 -4
- package/dist/cart-CcZ7rQyG.d.mts +176 -0
- package/dist/cart-D3o67Q3H.d.ts +176 -0
- package/dist/chunk-25OFOKNF.js +171 -0
- package/dist/chunk-25OFOKNF.js.map +1 -0
- package/dist/chunk-3DXPQ4YV.mjs +165 -0
- package/dist/chunk-3DXPQ4YV.mjs.map +1 -0
- package/dist/{chunk-4VJQZSPU.mjs → chunk-3NHAT7D4.mjs} +3 -4
- package/dist/chunk-3NHAT7D4.mjs.map +1 -0
- package/dist/{chunk-3JW4X3AC.mjs → chunk-622Y6LTH.mjs} +3 -3
- package/dist/{chunk-3JW4X3AC.mjs.map → chunk-622Y6LTH.mjs.map} +1 -1
- package/dist/chunk-ANKVXRPY.mjs +30 -0
- package/dist/chunk-ANKVXRPY.mjs.map +1 -0
- package/dist/chunk-CIVO4R6N.mjs +37 -0
- package/dist/chunk-CIVO4R6N.mjs.map +1 -0
- package/dist/{chunk-IZOIVYOW.js → chunk-DENROXAE.js} +2 -2
- package/dist/{chunk-IZOIVYOW.js.map → chunk-DENROXAE.js.map} +1 -1
- package/dist/{chunk-6BJ76BYC.mjs → chunk-EGJPS7OL.mjs} +3 -3
- package/dist/{chunk-6BJ76BYC.mjs.map → chunk-EGJPS7OL.mjs.map} +1 -1
- package/dist/chunk-EKIOJEJK.js +2719 -0
- package/dist/chunk-EKIOJEJK.js.map +1 -0
- package/dist/chunk-EOWTOG7Y.js +119 -0
- package/dist/chunk-EOWTOG7Y.js.map +1 -0
- package/dist/chunk-HDMIOOZY.mjs +546 -0
- package/dist/chunk-HDMIOOZY.mjs.map +1 -0
- package/dist/{chunk-MZKATHB7.js → chunk-HHVDOIPV.js} +4 -4
- package/dist/{chunk-MZKATHB7.js.map → chunk-HHVDOIPV.js.map} +1 -1
- package/dist/chunk-HJ6MH7J7.js +552 -0
- package/dist/chunk-HJ6MH7J7.js.map +1 -0
- package/dist/chunk-KH6RQ4J5.js +28 -0
- package/dist/chunk-KH6RQ4J5.js.map +1 -0
- package/dist/{chunk-GFVAIT6Y.mjs → chunk-MFG2Y6UR.mjs} +2 -2
- package/dist/{chunk-GFVAIT6Y.mjs.map → chunk-MFG2Y6UR.mjs.map} +1 -1
- package/dist/{chunk-35CXIK5Y.js → chunk-NCOXT7SK.js} +11 -11
- package/dist/{chunk-35CXIK5Y.js.map → chunk-NCOXT7SK.js.map} +1 -1
- package/dist/chunk-NZZZUMMX.mjs +784 -0
- package/dist/chunk-NZZZUMMX.mjs.map +1 -0
- package/dist/{chunk-OBIPI4GU.mjs → chunk-OFYBMMWT.mjs} +4 -4
- package/dist/{chunk-OBIPI4GU.mjs.map → chunk-OFYBMMWT.mjs.map} +1 -1
- package/dist/chunk-PVLLRDUT.js +6944 -0
- package/dist/chunk-PVLLRDUT.js.map +1 -0
- package/dist/chunk-Q5EDCKQA.js +336 -0
- package/dist/chunk-Q5EDCKQA.js.map +1 -0
- package/dist/{chunk-SHY424RZ.mjs → chunk-SNBILYSH.mjs} +6 -6
- package/dist/{chunk-SHY424RZ.mjs.map → chunk-SNBILYSH.mjs.map} +1 -1
- package/dist/chunk-TJZDPOO7.js +34 -0
- package/dist/chunk-TJZDPOO7.js.map +1 -0
- package/dist/{chunk-7JN25DJB.js → chunk-UVHPCLP6.js} +14 -14
- package/dist/{chunk-7JN25DJB.js.map → chunk-UVHPCLP6.js.map} +1 -1
- package/dist/chunk-WGD2NBVR.mjs +6904 -0
- package/dist/chunk-WGD2NBVR.mjs.map +1 -0
- package/dist/chunk-WS3QZYBI.mjs +2701 -0
- package/dist/chunk-WS3QZYBI.mjs.map +1 -0
- package/dist/chunk-XLR6QUDR.mjs +113 -0
- package/dist/chunk-XLR6QUDR.mjs.map +1 -0
- package/dist/chunk-YMS6BPXS.js +807 -0
- package/dist/chunk-YMS6BPXS.js.map +1 -0
- package/dist/chunk-YOTQG4NP.mjs +314 -0
- package/dist/chunk-YOTQG4NP.mjs.map +1 -0
- package/dist/chunk-ZGVB35L2.mjs +25 -0
- package/dist/chunk-ZGVB35L2.mjs.map +1 -0
- package/dist/chunk-ZRAW3HXA.js +43 -0
- package/dist/chunk-ZRAW3HXA.js.map +1 -0
- package/dist/{chunk-4XXIBWCO.js → chunk-ZRWED7Q6.js} +66 -66
- package/dist/{chunk-4XXIBWCO.js.map → chunk-ZRWED7Q6.js.map} +1 -1
- package/dist/{chunk-DVENFCQY.js → chunk-ZWQJSZEY.js} +4 -5
- package/dist/chunk-ZWQJSZEY.js.map +1 -0
- package/dist/components/index.js +104 -104
- package/dist/components/index.mjs +4 -4
- package/dist/index.js +146 -148
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -11
- package/dist/index.mjs.map +1 -1
- package/dist/logger/index.js +7 -7
- package/dist/logger/index.mjs +1 -4
- package/dist/mikuFusionGame/index.js +4 -4
- package/dist/mikuFusionGame/index.mjs +3 -3
- package/dist/portfolio/index.js +10 -10
- package/dist/portfolio/index.mjs +5 -5
- package/dist/showmasterpiece/db/index.d.mts +3028 -0
- package/dist/showmasterpiece/db/index.d.ts +3028 -0
- package/dist/showmasterpiece/db/index.js +179 -0
- package/dist/showmasterpiece/db/index.js.map +1 -0
- package/dist/showmasterpiece/db/index.mjs +6 -0
- package/dist/showmasterpiece/db/index.mjs.map +1 -0
- package/dist/showmasterpiece/index.d.mts +10 -1729
- package/dist/showmasterpiece/index.d.ts +10 -1729
- package/dist/showmasterpiece/index.js +439 -9659
- package/dist/showmasterpiece/index.js.map +1 -1
- package/dist/showmasterpiece/index.mjs +12 -9633
- package/dist/showmasterpiece/index.mjs.map +1 -1
- package/dist/showmasterpiece/logic/index.d.mts +372 -0
- package/dist/showmasterpiece/logic/index.d.ts +372 -0
- package/dist/showmasterpiece/logic/index.js +91 -0
- package/dist/showmasterpiece/logic/index.js.map +1 -0
- package/dist/showmasterpiece/logic/index.mjs +6 -0
- package/dist/showmasterpiece/logic/index.mjs.map +1 -0
- package/dist/showmasterpiece/server/index.d.mts +3 -2704
- package/dist/showmasterpiece/server/index.d.ts +3 -2704
- package/dist/showmasterpiece/server/index.js +43 -43
- package/dist/showmasterpiece/server/index.mjs +2 -2
- package/dist/showmasterpiece/ui/miniapp/index.d.mts +86 -0
- package/dist/showmasterpiece/ui/miniapp/index.d.ts +86 -0
- package/dist/showmasterpiece/ui/miniapp/index.js +196 -0
- package/dist/showmasterpiece/ui/miniapp/index.js.map +1 -0
- package/dist/showmasterpiece/ui/miniapp/index.mjs +183 -0
- package/dist/showmasterpiece/ui/miniapp/index.mjs.map +1 -0
- package/dist/showmasterpiece/ui/web/index.d.mts +600 -0
- package/dist/showmasterpiece/ui/web/index.d.ts +600 -0
- package/dist/showmasterpiece/ui/web/index.js +131 -0
- package/dist/showmasterpiece/ui/web/index.js.map +1 -0
- package/dist/showmasterpiece/ui/web/index.mjs +14 -0
- package/dist/showmasterpiece/ui/web/index.mjs.map +1 -0
- package/dist/universalExport/server/index.js +2 -4
- package/dist/universalExport/server/index.js.map +1 -1
- package/dist/universalExport/server/index.mjs +1 -3
- package/dist/universalExport/server/index.mjs.map +1 -1
- package/dist/universalFile/index.js +6 -9
- package/dist/universalFile/index.js.map +1 -1
- package/dist/universalFile/index.mjs +1 -5
- package/dist/universalFile/index.mjs.map +1 -1
- package/dist/universalFile/server/index.js +5852 -291
- package/dist/universalFile/server/index.js.map +1 -1
- package/dist/universalFile/server/index.mjs +5764 -8
- package/dist/universalFile/server/index.mjs.map +1 -1
- package/dist/utils/index.js +11 -11
- package/dist/utils/index.mjs +2 -2
- package/package.json +26 -1
- package/dist/AliyunOSSProvider-2FARPAQD.js +0 -15
- package/dist/AliyunOSSProvider-UMVGVBDJ.mjs +0 -9
- package/dist/LocalStorageProvider-JQF5WK5H.js +0 -15
- package/dist/LocalStorageProvider-PYOHETJV.mjs +0 -9
- package/dist/UniversalFileService-RBV6EN5J.js +0 -15
- package/dist/UniversalFileService-TNYKO6JN.mjs +0 -9
- package/dist/chunk-4NFOSCM6.js +0 -34
- package/dist/chunk-4NFOSCM6.js.map +0 -1
- package/dist/chunk-4VJQZSPU.mjs.map +0 -1
- package/dist/chunk-6AHYPPUP.js +0 -344
- package/dist/chunk-6AHYPPUP.js.map +0 -1
- package/dist/chunk-76V7EKBX.mjs +0 -796
- package/dist/chunk-76V7EKBX.mjs.map +0 -1
- package/dist/chunk-ACLOJXXE.js +0 -195
- package/dist/chunk-ACLOJXXE.js.map +0 -1
- package/dist/chunk-AEXPAH7Z.mjs +0 -32
- package/dist/chunk-AEXPAH7Z.mjs.map +0 -1
- package/dist/chunk-CFGX3EKK.js +0 -560
- package/dist/chunk-CFGX3EKK.js.map +0 -1
- package/dist/chunk-D2HXMGXS.js +0 -46
- package/dist/chunk-D2HXMGXS.js.map +0 -1
- package/dist/chunk-DVENFCQY.js.map +0 -1
- package/dist/chunk-K7WNCB4V.mjs +0 -554
- package/dist/chunk-K7WNCB4V.mjs.map +0 -1
- package/dist/chunk-L4ZYBFB2.mjs +0 -44
- package/dist/chunk-L4ZYBFB2.mjs.map +0 -1
- package/dist/chunk-M4HGHTIC.js +0 -820
- package/dist/chunk-M4HGHTIC.js.map +0 -1
- package/dist/chunk-PKKIDPXE.mjs +0 -5797
- package/dist/chunk-PKKIDPXE.mjs.map +0 -1
- package/dist/chunk-PXWDQFWV.mjs +0 -192
- package/dist/chunk-PXWDQFWV.mjs.map +0 -1
- package/dist/chunk-TSTBLX6B.js +0 -5888
- package/dist/chunk-TSTBLX6B.js.map +0 -1
- package/dist/chunk-VTGPHE4Z.mjs +0 -322
- package/dist/chunk-VTGPHE4Z.mjs.map +0 -1
- package/dist/popupConfig-BznThU1O.d.mts +0 -330
- package/dist/popupConfig-BznThU1O.d.ts +0 -330
- package/dist/showmasterpiece/migration/index.d.mts +0 -120
- package/dist/showmasterpiece/migration/index.d.ts +0 -120
- package/dist/showmasterpiece/migration/index.js +0 -595
- package/dist/showmasterpiece/migration/index.js.map +0 -1
- package/dist/showmasterpiece/migration/index.mjs +0 -589
- package/dist/showmasterpiece/migration/index.mjs.map +0 -1
- package/dist/showmasterpiece/scripts/index.d.mts +0 -28
- package/dist/showmasterpiece/scripts/index.d.ts +0 -28
- package/dist/showmasterpiece/scripts/index.js +0 -327
- package/dist/showmasterpiece/scripts/index.js.map +0 -1
- package/dist/showmasterpiece/scripts/index.mjs +0 -325
- package/dist/showmasterpiece/scripts/index.mjs.map +0 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkEKIOJEJK_js = require('./chunk-EKIOJEJK.js');
|
|
4
|
+
|
|
5
|
+
// src/showmasterpiece/logic/index.ts
|
|
6
|
+
chunkEKIOJEJK_js.init_hooks();
|
|
7
|
+
|
|
8
|
+
// src/showmasterpiece/logic/contexts/index.ts
|
|
9
|
+
chunkEKIOJEJK_js.init_CartContext();
|
|
10
|
+
chunkEKIOJEJK_js.init_hooks();
|
|
11
|
+
|
|
12
|
+
// src/showmasterpiece/logic/shared/storage.ts
|
|
13
|
+
var hasWxStorage = () => typeof wx !== "undefined" && typeof wx.getStorageSync === "function";
|
|
14
|
+
var hasLocalStorage = () => typeof localStorage !== "undefined" && typeof localStorage.getItem === "function";
|
|
15
|
+
var getStorageSync = (key) => {
|
|
16
|
+
try {
|
|
17
|
+
if (hasWxStorage()) {
|
|
18
|
+
return wx.getStorageSync(key);
|
|
19
|
+
}
|
|
20
|
+
if (hasLocalStorage()) {
|
|
21
|
+
const value = localStorage.getItem(key);
|
|
22
|
+
return value ? JSON.parse(value) : null;
|
|
23
|
+
}
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
var setStorageSync = (key, value) => {
|
|
30
|
+
try {
|
|
31
|
+
if (hasWxStorage()) {
|
|
32
|
+
wx.setStorageSync(key, value);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (hasLocalStorage()) {
|
|
36
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
37
|
+
}
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/showmasterpiece/logic/shared/cart.ts
|
|
43
|
+
var CART_STORAGE_KEY = "showmasterpiece_cart";
|
|
44
|
+
var normalizeCart = (cart) => {
|
|
45
|
+
const safeCart = cart ?? { items: [], totalPrice: 0, totalQuantity: 0 };
|
|
46
|
+
const totals = safeCart.items.reduce(
|
|
47
|
+
(acc, item) => {
|
|
48
|
+
acc.totalQuantity += item.quantity;
|
|
49
|
+
acc.totalPrice += (item.collection.price || 0) * item.quantity;
|
|
50
|
+
return acc;
|
|
51
|
+
},
|
|
52
|
+
{ totalQuantity: 0, totalPrice: 0 }
|
|
53
|
+
);
|
|
54
|
+
return {
|
|
55
|
+
...safeCart,
|
|
56
|
+
totalQuantity: totals.totalQuantity,
|
|
57
|
+
totalPrice: totals.totalPrice
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
var getCart = () => {
|
|
61
|
+
const stored = getStorageSync(CART_STORAGE_KEY);
|
|
62
|
+
if (stored && stored.items) {
|
|
63
|
+
return normalizeCart(stored);
|
|
64
|
+
}
|
|
65
|
+
return normalizeCart();
|
|
66
|
+
};
|
|
67
|
+
var saveCart = (cart) => {
|
|
68
|
+
setStorageSync(CART_STORAGE_KEY, cart);
|
|
69
|
+
};
|
|
70
|
+
var addToCart = (collection, quantity = 1) => {
|
|
71
|
+
const cart = getCart();
|
|
72
|
+
const existing = cart.items.find((item) => item.collectionId === collection.id);
|
|
73
|
+
if (existing) {
|
|
74
|
+
existing.quantity += quantity;
|
|
75
|
+
} else {
|
|
76
|
+
cart.items.push({
|
|
77
|
+
collectionId: collection.id,
|
|
78
|
+
collection,
|
|
79
|
+
quantity,
|
|
80
|
+
addedAt: /* @__PURE__ */ new Date()
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const next = normalizeCart(cart);
|
|
84
|
+
saveCart(next);
|
|
85
|
+
return next;
|
|
86
|
+
};
|
|
87
|
+
var updateCartItem = (collectionId, quantity) => {
|
|
88
|
+
const cart = getCart();
|
|
89
|
+
const target = cart.items.find((item) => item.collectionId === collectionId);
|
|
90
|
+
if (!target) return cart;
|
|
91
|
+
if (quantity <= 0) {
|
|
92
|
+
cart.items = cart.items.filter((item) => item.collectionId !== collectionId);
|
|
93
|
+
} else {
|
|
94
|
+
target.quantity = quantity;
|
|
95
|
+
}
|
|
96
|
+
const next = normalizeCart(cart);
|
|
97
|
+
saveCart(next);
|
|
98
|
+
return next;
|
|
99
|
+
};
|
|
100
|
+
var removeCartItem = (collectionId) => {
|
|
101
|
+
const cart = getCart();
|
|
102
|
+
cart.items = cart.items.filter((item) => item.collectionId !== collectionId);
|
|
103
|
+
const next = normalizeCart(cart);
|
|
104
|
+
saveCart(next);
|
|
105
|
+
return next;
|
|
106
|
+
};
|
|
107
|
+
var clearCart = () => {
|
|
108
|
+
const empty = normalizeCart({ items: [], totalPrice: 0, totalQuantity: 0 });
|
|
109
|
+
saveCart(empty);
|
|
110
|
+
return empty;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
exports.addToCart = addToCart;
|
|
114
|
+
exports.clearCart = clearCart;
|
|
115
|
+
exports.getCart = getCart;
|
|
116
|
+
exports.removeCartItem = removeCartItem;
|
|
117
|
+
exports.updateCartItem = updateCartItem;
|
|
118
|
+
//# sourceMappingURL=chunk-EOWTOG7Y.js.map
|
|
119
|
+
//# sourceMappingURL=chunk-EOWTOG7Y.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/showmasterpiece/logic/index.ts","../src/showmasterpiece/logic/contexts/index.ts","../src/showmasterpiece/logic/shared/storage.ts","../src/showmasterpiece/logic/shared/cart.ts"],"names":["init_hooks","init_CartContext"],"mappings":"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","file":"chunk-EOWTOG7Y.js","sourcesContent":["export * from './hooks';\nexport * from './contexts';\nexport * from './shared';\n","export { CartProvider } from './CartContext';\nexport { useCartContext } from '../hooks';\n","declare const wx: any;\n\nconst hasWxStorage = (): boolean =>\n typeof wx !== 'undefined' && typeof (wx as any).getStorageSync === 'function';\n\nconst hasLocalStorage = (): boolean =>\n typeof localStorage !== 'undefined' && typeof localStorage.getItem === 'function';\n\nexport const getStorageSync = <T>(key: string): T | null => {\n try {\n if (hasWxStorage()) {\n return (wx as any).getStorageSync(key) as T;\n }\n if (hasLocalStorage()) {\n const value = localStorage.getItem(key);\n return value ? (JSON.parse(value) as T) : null;\n }\n } catch {\n return null;\n }\n return null;\n};\n\nexport const setStorageSync = (key: string, value: unknown): void => {\n try {\n if (hasWxStorage()) {\n (wx as any).setStorageSync(key, value);\n return;\n }\n if (hasLocalStorage()) {\n localStorage.setItem(key, JSON.stringify(value));\n }\n } catch {\n // ignore\n }\n};\n","import type { Cart } from '../../types/cart';\nimport type { ArtCollection } from '../../types';\nimport { getStorageSync, setStorageSync } from './storage';\n\nconst CART_STORAGE_KEY = 'showmasterpiece_cart';\n\nconst normalizeCart = (cart?: Cart): Cart => {\n const safeCart: Cart = cart ?? { items: [], totalPrice: 0, totalQuantity: 0 };\n const totals = safeCart.items.reduce(\n (acc, item) => {\n acc.totalQuantity += item.quantity;\n acc.totalPrice += (item.collection.price || 0) * item.quantity;\n return acc;\n },\n { totalQuantity: 0, totalPrice: 0 }\n );\n\n return {\n ...safeCart,\n totalQuantity: totals.totalQuantity,\n totalPrice: totals.totalPrice\n };\n};\n\nexport const getCart = (): Cart => {\n const stored = getStorageSync<Cart>(CART_STORAGE_KEY);\n if (stored && stored.items) {\n return normalizeCart(stored);\n }\n return normalizeCart();\n};\n\nconst saveCart = (cart: Cart) => {\n setStorageSync(CART_STORAGE_KEY, cart);\n};\n\nexport const addToCart = (collection: ArtCollection, quantity = 1): Cart => {\n const cart = getCart();\n const existing = cart.items.find(item => item.collectionId === collection.id);\n\n if (existing) {\n existing.quantity += quantity;\n } else {\n cart.items.push({\n collectionId: collection.id,\n collection,\n quantity,\n addedAt: new Date()\n });\n }\n\n const next = normalizeCart(cart);\n saveCart(next);\n return next;\n};\n\nexport const updateCartItem = (collectionId: number, quantity: number): Cart => {\n const cart = getCart();\n const target = cart.items.find(item => item.collectionId === collectionId);\n if (!target) return cart;\n\n if (quantity <= 0) {\n cart.items = cart.items.filter(item => item.collectionId !== collectionId);\n } else {\n target.quantity = quantity;\n }\n\n const next = normalizeCart(cart);\n saveCart(next);\n return next;\n};\n\nexport const removeCartItem = (collectionId: number): Cart => {\n const cart = getCart();\n cart.items = cart.items.filter(item => item.collectionId !== collectionId);\n const next = normalizeCart(cart);\n saveCart(next);\n return next;\n};\n\nexport const clearCart = (): Cart => {\n const empty = normalizeCart({ items: [], totalPrice: 0, totalQuantity: 0 });\n saveCart(empty);\n return empty;\n};\n"]}
|
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
import { StorageProviderError } from './chunk-ZGVB35L2.mjs';
|
|
2
|
+
import { createLogger } from './chunk-3DXPQ4YV.mjs';
|
|
3
|
+
import OSS from 'ali-oss';
|
|
4
|
+
|
|
5
|
+
var logger = createLogger("AliyunOSSProvider");
|
|
6
|
+
var AliyunOSSProvider = class {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.type = "aliyun-oss";
|
|
9
|
+
this.config = null;
|
|
10
|
+
this.client = null;
|
|
11
|
+
this.isInitialized = false;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 初始化存储提供者
|
|
15
|
+
*/
|
|
16
|
+
async initialize(config) {
|
|
17
|
+
return this.reinitialize(config);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 重新初始化存储提供者(支持配置热更新)
|
|
21
|
+
*/
|
|
22
|
+
async reinitialize(config) {
|
|
23
|
+
logger.info("\u{1F504} [AliyunOSSProvider] \u91CD\u65B0\u521D\u59CB\u5316OSS\u5BA2\u6237\u7AEF", config);
|
|
24
|
+
if (config.type !== "aliyun-oss") {
|
|
25
|
+
throw new StorageProviderError("\u914D\u7F6E\u7C7B\u578B\u4E0D\u5339\u914D\uFF1A\u671F\u671B aliyun-oss");
|
|
26
|
+
}
|
|
27
|
+
const newConfig = config;
|
|
28
|
+
const configChanged = !this.config || this.config.region !== newConfig.region || this.config.bucket !== newConfig.bucket || this.config.accessKeyId !== newConfig.accessKeyId || this.config.accessKeySecret !== newConfig.accessKeySecret || this.config.customDomain !== newConfig.customDomain || this.config.secure !== newConfig.secure || this.config.internal !== newConfig.internal;
|
|
29
|
+
if (configChanged) {
|
|
30
|
+
logger.info("\u{1F504} [AliyunOSSProvider] \u68C0\u6D4B\u5230\u914D\u7F6E\u53D8\u5316\uFF0C\u91CD\u65B0\u521D\u59CB\u5316OSS\u5BA2\u6237\u7AEF");
|
|
31
|
+
logger.info(
|
|
32
|
+
"\u2601\uFE0F [AliyunOSSProvider] \u65B0\u914D\u7F6E: bucket=" + newConfig.bucket + ", region=" + newConfig.region
|
|
33
|
+
);
|
|
34
|
+
} else if (this.isInitialized) {
|
|
35
|
+
logger.info("\u2139\uFE0F [AliyunOSSProvider] \u914D\u7F6E\u672A\u53D8\u5316\uFF0C\u8DF3\u8FC7\u91CD\u65B0\u521D\u59CB\u5316");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.config = newConfig;
|
|
39
|
+
logger.info("\u2601\uFE0F [AliyunOSSProvider] " + (this.isInitialized ? "\u91CD\u65B0" : "") + "\u521D\u59CB\u5316\u963F\u91CC\u4E91OSS");
|
|
40
|
+
logger.info("\u2601\uFE0F [AliyunOSSProvider] " + (this.config ? JSON.stringify(this.config) : ""));
|
|
41
|
+
try {
|
|
42
|
+
this.validateConfig();
|
|
43
|
+
if (!this.config.region || typeof this.config.region !== "string") {
|
|
44
|
+
throw new Error("OSS region \u5FC5\u987B\u662F\u6709\u6548\u7684\u5B57\u7B26\u4E32");
|
|
45
|
+
}
|
|
46
|
+
if (!this.config.bucket || typeof this.config.bucket !== "string") {
|
|
47
|
+
throw new Error("OSS bucket \u5FC5\u987B\u662F\u6709\u6548\u7684\u5B57\u7B26\u4E32");
|
|
48
|
+
}
|
|
49
|
+
if (!this.config.accessKeyId || typeof this.config.accessKeyId !== "string") {
|
|
50
|
+
throw new Error("OSS accessKeyId \u5FC5\u987B\u662F\u6709\u6548\u7684\u5B57\u7B26\u4E32");
|
|
51
|
+
}
|
|
52
|
+
if (!this.config.accessKeySecret || typeof this.config.accessKeySecret !== "string") {
|
|
53
|
+
throw new Error("OSS accessKeySecret \u5FC5\u987B\u662F\u6709\u6548\u7684\u5B57\u7B26\u4E32");
|
|
54
|
+
}
|
|
55
|
+
logger.info(`\u2601\uFE0F [AliyunOSSProvider] \u521B\u5EFAOSS\u5BA2\u6237\u7AEF\u914D\u7F6E:`, {
|
|
56
|
+
region: this.config.region,
|
|
57
|
+
bucket: this.config.bucket,
|
|
58
|
+
hasAccessKeyId: !!this.config.accessKeyId,
|
|
59
|
+
hasAccessKeySecret: !!this.config.accessKeySecret,
|
|
60
|
+
secure: this.config.secure !== false,
|
|
61
|
+
internal: this.config.internal || false,
|
|
62
|
+
cname: !!this.config.customDomain,
|
|
63
|
+
endpoint: this.config.customDomain || "\u9ED8\u8BA4\u7AEF\u70B9"
|
|
64
|
+
});
|
|
65
|
+
this.client = new OSS({
|
|
66
|
+
region: this.config.region,
|
|
67
|
+
bucket: this.config.bucket,
|
|
68
|
+
accessKeyId: this.config.accessKeyId,
|
|
69
|
+
accessKeySecret: this.config.accessKeySecret,
|
|
70
|
+
secure: this.config.secure !== false,
|
|
71
|
+
// 默认使用HTTPS
|
|
72
|
+
internal: this.config.internal || false,
|
|
73
|
+
// 默认使用公网
|
|
74
|
+
timeout: 3e5,
|
|
75
|
+
// 5分钟超时
|
|
76
|
+
cname: !!this.config.customDomain,
|
|
77
|
+
// 是否使用自定义域名
|
|
78
|
+
endpoint: this.config.customDomain || void 0
|
|
79
|
+
});
|
|
80
|
+
if (!this.client) {
|
|
81
|
+
throw new Error("OSS\u5BA2\u6237\u7AEF\u521B\u5EFA\u5931\u8D25");
|
|
82
|
+
}
|
|
83
|
+
logger.info(`\u2601\uFE0F [AliyunOSSProvider] OSS\u5BA2\u6237\u7AEF\u521B\u5EFA\u6210\u529F`);
|
|
84
|
+
this.isInitialized = true;
|
|
85
|
+
logger.info("\u2705 [AliyunOSSProvider] \u963F\u91CC\u4E91OSS" + (configChanged ? "\u91CD\u65B0" : "") + "\u521D\u59CB\u5316\u5B8C\u6210");
|
|
86
|
+
} catch (error) {
|
|
87
|
+
logger.error("\u274C [AliyunOSSProvider] \u963F\u91CC\u4E91OSS\u521D\u59CB\u5316\u5931\u8D25:", error);
|
|
88
|
+
throw new StorageProviderError(`\u963F\u91CC\u4E91OSS\u521D\u59CB\u5316\u5931\u8D25`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 上传文件
|
|
93
|
+
*/
|
|
94
|
+
async upload(fileInfo, filePath) {
|
|
95
|
+
this.ensureInitialized();
|
|
96
|
+
const startTime = Date.now();
|
|
97
|
+
logger.info("\u{1F4E4} [AliyunOSSProvider] \u5F00\u59CB\u4E0A\u4F20\u6587\u4EF6\u5230OSS: " + filePath);
|
|
98
|
+
try {
|
|
99
|
+
const buffer = Buffer.from(await fileInfo.file.arrayBuffer());
|
|
100
|
+
const options = {
|
|
101
|
+
headers: {
|
|
102
|
+
"Content-Type": fileInfo.file.type || "application/octet-stream",
|
|
103
|
+
"Content-Length": fileInfo.file.size.toString()
|
|
104
|
+
},
|
|
105
|
+
meta: {
|
|
106
|
+
uid: 0,
|
|
107
|
+
// 必需字段
|
|
108
|
+
pid: 0,
|
|
109
|
+
// 必需字段
|
|
110
|
+
originalName: encodeURIComponent(fileInfo.file.name),
|
|
111
|
+
moduleId: fileInfo.moduleId,
|
|
112
|
+
businessId: fileInfo.businessId || "",
|
|
113
|
+
uploadTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
114
|
+
// 对元数据进行编码处理,避免中文字符问题
|
|
115
|
+
...this.encodeMetadata(fileInfo.metadata || {})
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
let result;
|
|
119
|
+
if (fileInfo.file.size > 100 * 1024 * 1024) {
|
|
120
|
+
logger.info(
|
|
121
|
+
"\u{1F4E6} [AliyunOSSProvider] \u4F7F\u7528\u5206\u7247\u4E0A\u4F20\u5927\u6587\u4EF6: " + filePath + ", \u5927\u5C0F: " + fileInfo.file.size
|
|
122
|
+
);
|
|
123
|
+
result = await this.multipartUpload(filePath, buffer, options);
|
|
124
|
+
} else {
|
|
125
|
+
logger.info(
|
|
126
|
+
"\u{1F4E4} [AliyunOSSProvider] \u4F7F\u7528\u666E\u901A\u4E0A\u4F20: " + filePath + ", \u5927\u5C0F: " + fileInfo.file.size
|
|
127
|
+
);
|
|
128
|
+
result = await this.client?.put(filePath, buffer, options);
|
|
129
|
+
}
|
|
130
|
+
const accessUrl = this.generateAccessUrl(filePath);
|
|
131
|
+
const uploadTime = Date.now() - startTime;
|
|
132
|
+
logger.info("\u2705 [AliyunOSSProvider] \u6587\u4EF6\u4E0A\u4F20\u5B8C\u6210: " + filePath + ", \u8017\u65F6: " + uploadTime + "ms");
|
|
133
|
+
return {
|
|
134
|
+
success: true,
|
|
135
|
+
path: filePath,
|
|
136
|
+
url: accessUrl,
|
|
137
|
+
size: fileInfo.file.size,
|
|
138
|
+
data: {
|
|
139
|
+
etag: result.data ? JSON.stringify(result.data) : "",
|
|
140
|
+
requestId: result.res?.rt || 0,
|
|
141
|
+
uploadTime,
|
|
142
|
+
ossUrl: result.url || result.name
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
} catch (error) {
|
|
146
|
+
logger.error("\u274C [AliyunOSSProvider] \u6587\u4EF6\u4E0A\u4F20\u5931\u8D25: " + filePath + ":", error);
|
|
147
|
+
return {
|
|
148
|
+
success: false,
|
|
149
|
+
error: this.formatOSSError(error)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 下载文件
|
|
155
|
+
*/
|
|
156
|
+
async download(filePath) {
|
|
157
|
+
this.ensureInitialized();
|
|
158
|
+
logger.info("\u{1F4E5} [AliyunOSSProvider] \u5F00\u59CB\u4ECEOSS\u4E0B\u8F7D\u6587\u4EF6: " + filePath);
|
|
159
|
+
try {
|
|
160
|
+
const result = await this.client?.get(filePath);
|
|
161
|
+
if (!result.content || !Buffer.isBuffer(result.content)) {
|
|
162
|
+
throw new StorageProviderError("\u4E0B\u8F7D\u7684\u6587\u4EF6\u5185\u5BB9\u683C\u5F0F\u9519\u8BEF");
|
|
163
|
+
}
|
|
164
|
+
logger.info(
|
|
165
|
+
"\u2705 [AliyunOSSProvider] \u6587\u4EF6\u4E0B\u8F7D\u5B8C\u6210: " + filePath + ", \u5927\u5C0F: " + result.content.length
|
|
166
|
+
);
|
|
167
|
+
return result.content;
|
|
168
|
+
} catch (error) {
|
|
169
|
+
logger.error("\u274C [AliyunOSSProvider] \u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25: " + filePath + ":", error);
|
|
170
|
+
if (this.isOSSError(error) && error.code === "NoSuchKey") {
|
|
171
|
+
throw new StorageProviderError(`\u6587\u4EF6\u4E0D\u5B58\u5728`);
|
|
172
|
+
}
|
|
173
|
+
throw new StorageProviderError(`\u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* 删除文件
|
|
178
|
+
*/
|
|
179
|
+
async delete(filePath) {
|
|
180
|
+
this.ensureInitialized();
|
|
181
|
+
logger.info("\u{1F5D1}\uFE0F [AliyunOSSProvider] \u5F00\u59CB\u4ECEOSS\u5220\u9664\u6587\u4EF6: " + filePath);
|
|
182
|
+
try {
|
|
183
|
+
const result = await this.client?.delete(filePath);
|
|
184
|
+
logger.info("\u2705 [AliyunOSSProvider] \u6587\u4EF6\u5220\u9664\u5B8C\u6210: " + filePath);
|
|
185
|
+
return {
|
|
186
|
+
success: true,
|
|
187
|
+
data: {
|
|
188
|
+
requestId: result?.res?.rt || 0,
|
|
189
|
+
deletedPath: filePath
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
} catch (error) {
|
|
193
|
+
logger.error("\u274C [AliyunOSSProvider] \u6587\u4EF6\u5220\u9664\u5931\u8D25: " + filePath + ":", error);
|
|
194
|
+
if (this.isOSSError(error) && error.code === "NoSuchKey") {
|
|
195
|
+
logger.warn("\u26A0\uFE0F [AliyunOSSProvider] \u6587\u4EF6\u4E0D\u5B58\u5728: " + filePath);
|
|
196
|
+
return {
|
|
197
|
+
success: true,
|
|
198
|
+
data: { reason: "file_not_exists" }
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
success: false,
|
|
203
|
+
error: this.formatOSSError(error)
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* 获取文件信息
|
|
209
|
+
*/
|
|
210
|
+
async getFileInfo(filePath) {
|
|
211
|
+
this.ensureInitialized();
|
|
212
|
+
try {
|
|
213
|
+
const result = await this.client?.head(filePath);
|
|
214
|
+
return {
|
|
215
|
+
success: true,
|
|
216
|
+
size: parseInt(String(result.meta["content-length"] || "0")),
|
|
217
|
+
data: {
|
|
218
|
+
etag: result.meta.etag || "",
|
|
219
|
+
lastModified: result.meta["last-modified"] || "",
|
|
220
|
+
contentType: result.meta["content-type"],
|
|
221
|
+
meta: result.meta,
|
|
222
|
+
size: parseInt(String(result.meta["content-length"] || "0"))
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
} catch (error) {
|
|
226
|
+
if (this.isOSSError(error) && error.code === "NoSuchKey") {
|
|
227
|
+
return {
|
|
228
|
+
success: false,
|
|
229
|
+
error: "\u6587\u4EF6\u4E0D\u5B58\u5728"
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
success: false,
|
|
234
|
+
error: this.formatOSSError(error)
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* 生成访问URL
|
|
240
|
+
*/
|
|
241
|
+
async getAccessUrl(filePath, expiresIn) {
|
|
242
|
+
this.ensureInitialized();
|
|
243
|
+
try {
|
|
244
|
+
const isImage = /\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)$/i.test(filePath);
|
|
245
|
+
if (isImage) {
|
|
246
|
+
return this.generateAccessUrl(filePath);
|
|
247
|
+
} else {
|
|
248
|
+
const expires = expiresIn || 3600;
|
|
249
|
+
const signedUrl = this.client?.signatureUrl(filePath, {
|
|
250
|
+
expires,
|
|
251
|
+
method: "GET"
|
|
252
|
+
});
|
|
253
|
+
return signedUrl || "";
|
|
254
|
+
}
|
|
255
|
+
} catch (error) {
|
|
256
|
+
logger.error("\u274C [AliyunOSSProvider] \u751F\u6210\u8BBF\u95EEURL\u5931\u8D25: " + filePath + ":", error);
|
|
257
|
+
throw new StorageProviderError(`\u751F\u6210\u8BBF\u95EEURL\u5931\u8D25`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* 生成预签名上传URL
|
|
262
|
+
*/
|
|
263
|
+
async getUploadUrl(filePath, expiresIn) {
|
|
264
|
+
this.ensureInitialized();
|
|
265
|
+
try {
|
|
266
|
+
const expires = expiresIn || 3600;
|
|
267
|
+
const signedUrl = this.client?.signatureUrl(filePath, {
|
|
268
|
+
expires,
|
|
269
|
+
method: "PUT"
|
|
270
|
+
});
|
|
271
|
+
return signedUrl || "";
|
|
272
|
+
} catch (error) {
|
|
273
|
+
logger.error("\u274C [AliyunOSSProvider] \u751F\u6210\u4E0A\u4F20URL\u5931\u8D25: " + filePath + ":", error);
|
|
274
|
+
throw new StorageProviderError(`\u751F\u6210\u4E0A\u4F20URL\u5931\u8D25`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* 检查文件是否存在
|
|
279
|
+
*/
|
|
280
|
+
async exists(filePath) {
|
|
281
|
+
this.ensureInitialized();
|
|
282
|
+
try {
|
|
283
|
+
await this.client?.head(filePath);
|
|
284
|
+
return true;
|
|
285
|
+
} catch (error) {
|
|
286
|
+
if (this.isOSSError(error) && error.code === "NoSuchKey") {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
logger.warn("\u26A0\uFE0F [AliyunOSSProvider] \u68C0\u67E5\u6587\u4EF6\u5B58\u5728\u6027\u65F6\u51FA\u9519: " + filePath + ":", error);
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* 列出文件(详细信息)
|
|
295
|
+
*/
|
|
296
|
+
async listFiles(prefix, delimiter = "/", maxKeys = 1e3) {
|
|
297
|
+
this.ensureInitialized();
|
|
298
|
+
try {
|
|
299
|
+
const options = {
|
|
300
|
+
prefix,
|
|
301
|
+
delimiter,
|
|
302
|
+
"max-keys": String(maxKeys)
|
|
303
|
+
};
|
|
304
|
+
const result = await this.client?.list(options, {});
|
|
305
|
+
const files = (result.objects || []).map((obj) => ({
|
|
306
|
+
name: obj.name,
|
|
307
|
+
url: this.generateAccessUrl(obj.name),
|
|
308
|
+
size: obj.size,
|
|
309
|
+
lastModified: obj.lastModified,
|
|
310
|
+
etag: obj.etag,
|
|
311
|
+
type: "file"
|
|
312
|
+
}));
|
|
313
|
+
const folders = result.prefixes || [];
|
|
314
|
+
return {
|
|
315
|
+
files,
|
|
316
|
+
folders,
|
|
317
|
+
nextMarker: result.nextMarker
|
|
318
|
+
};
|
|
319
|
+
} catch (error) {
|
|
320
|
+
logger.error("\u274C [AliyunOSSProvider] \u5217\u51FA\u6587\u4EF6\u5931\u8D25: " + prefix + ":", error);
|
|
321
|
+
throw new StorageProviderError(`\u5217\u51FA\u6587\u4EF6\u5931\u8D25`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* 列出文件
|
|
326
|
+
*/
|
|
327
|
+
async list(prefix, maxKeys) {
|
|
328
|
+
this.ensureInitialized();
|
|
329
|
+
try {
|
|
330
|
+
const options = {
|
|
331
|
+
prefix,
|
|
332
|
+
"max-keys": String(maxKeys || 1e3)
|
|
333
|
+
};
|
|
334
|
+
const result = await this.client?.list(options, {});
|
|
335
|
+
return result.objects?.map((obj) => obj.name) || [];
|
|
336
|
+
} catch (error) {
|
|
337
|
+
logger.error("\u274C [AliyunOSSProvider] \u5217\u51FA\u6587\u4EF6\u5931\u8D25: " + prefix + ":", error);
|
|
338
|
+
return [];
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
// ============= 私有方法 =============
|
|
342
|
+
/**
|
|
343
|
+
* 确保已初始化
|
|
344
|
+
*/
|
|
345
|
+
ensureInitialized() {
|
|
346
|
+
if (!this.isInitialized || !this.client || !this.config) {
|
|
347
|
+
throw new StorageProviderError("OSS\u5B58\u50A8\u63D0\u4F9B\u8005\u672A\u521D\u59CB\u5316");
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* 验证配置
|
|
352
|
+
*/
|
|
353
|
+
validateConfig() {
|
|
354
|
+
if (!this.config) {
|
|
355
|
+
throw new StorageProviderError("OSS\u914D\u7F6E\u4E3A\u7A7A");
|
|
356
|
+
}
|
|
357
|
+
const required = ["region", "bucket", "accessKeyId", "accessKeySecret"];
|
|
358
|
+
const missing = required.filter((key) => !this.config[key]);
|
|
359
|
+
if (missing.length > 0) {
|
|
360
|
+
throw new StorageProviderError(`OSS\u914D\u7F6E\u7F3A\u5C11\u5FC5\u9700\u9879`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* 测试连接
|
|
365
|
+
*/
|
|
366
|
+
async testConnection() {
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* 分片上传大文件
|
|
370
|
+
*/
|
|
371
|
+
async multipartUpload(filePath, buffer, options) {
|
|
372
|
+
logger.info(`\u{1F4E6} [AliyunOSSProvider] \u4F7F\u7528\u591A\u5206\u7247\u4E0A\u4F20`);
|
|
373
|
+
const result = await this.client?.multipartUpload(filePath, buffer, {
|
|
374
|
+
partSize: 10 * 1024 * 1024,
|
|
375
|
+
// 10MB per chunk
|
|
376
|
+
parallel: 4,
|
|
377
|
+
// 并发数
|
|
378
|
+
progress: (p) => {
|
|
379
|
+
if (p % 0.1 < 0.01) {
|
|
380
|
+
logger.info("\u{1F4E6} [AliyunOSSProvider] \u4E0A\u4F20\u8FDB\u5EA6: " + (p * 100).toFixed(1) + "%");
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
meta: options.meta,
|
|
384
|
+
headers: options.headers
|
|
385
|
+
});
|
|
386
|
+
return {
|
|
387
|
+
name: result?.name || "",
|
|
388
|
+
url: result?.name || "",
|
|
389
|
+
// OSS返回的是object名称
|
|
390
|
+
data: result?.data || {},
|
|
391
|
+
res: result?.res || {}
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* 生成公开访问URL
|
|
396
|
+
*/
|
|
397
|
+
generateAccessUrl(filePath) {
|
|
398
|
+
if (!this.config) {
|
|
399
|
+
throw new StorageProviderError("OSS\u914D\u7F6E\u4E3A\u7A7A");
|
|
400
|
+
}
|
|
401
|
+
const normalizedPath = filePath.startsWith("/") ? filePath.substring(1) : filePath;
|
|
402
|
+
if (this.config.customDomain) {
|
|
403
|
+
const protocol = this.config.secure !== false ? "https" : "http";
|
|
404
|
+
const url = protocol + "://" + this.config.customDomain + "/" + normalizedPath;
|
|
405
|
+
logger.info("\u{1F517} [AliyunOSSProvider] \u4F7F\u7528\u81EA\u5B9A\u4E49\u57DF\u540D: " + url);
|
|
406
|
+
return url;
|
|
407
|
+
} else {
|
|
408
|
+
const protocol = this.config.secure !== false ? "https" : "http";
|
|
409
|
+
const url = protocol + "://" + this.config.bucket + "." + this.config.region + ".aliyuncs.com/" + normalizedPath;
|
|
410
|
+
logger.info("\u{1F517} [AliyunOSSProvider] \u4F7F\u7528\u9ED8\u8BA4OSS\u57DF\u540D: " + url);
|
|
411
|
+
return url;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* 判断是否为OSS错误
|
|
416
|
+
*/
|
|
417
|
+
isOSSError(error) {
|
|
418
|
+
if (!error || typeof error !== "object") {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
return typeof error.code === "string" && typeof (error.name || "") === "string" && typeof (error.message || "") === "string";
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* 格式化OSS错误信息
|
|
425
|
+
*/
|
|
426
|
+
formatOSSError(error) {
|
|
427
|
+
if (error instanceof Error) {
|
|
428
|
+
return error.message;
|
|
429
|
+
}
|
|
430
|
+
if (typeof error === "string") {
|
|
431
|
+
return error;
|
|
432
|
+
}
|
|
433
|
+
return "\u672A\u77E5\u9519\u8BEF";
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* 流式上传(可选实现)
|
|
437
|
+
*/
|
|
438
|
+
async uploadStream(readableStream, filePath, contentType, contentLength) {
|
|
439
|
+
this.ensureInitialized();
|
|
440
|
+
const startTime = Date.now();
|
|
441
|
+
logger.info("\u{1F4E4} [AliyunOSSProvider] \u5F00\u59CB\u6D41\u5F0F\u4E0A\u4F20\u6587\u4EF6\u5230OSS: " + filePath);
|
|
442
|
+
try {
|
|
443
|
+
const options = {
|
|
444
|
+
timeout: 3e5,
|
|
445
|
+
mime: contentType || "application/octet-stream",
|
|
446
|
+
meta: { uid: 0, pid: 0 },
|
|
447
|
+
callback: { url: "", body: "" },
|
|
448
|
+
headers: {}
|
|
449
|
+
};
|
|
450
|
+
if (contentLength) {
|
|
451
|
+
options.headers["Content-Length"] = contentLength.toString();
|
|
452
|
+
}
|
|
453
|
+
const result = await this.client?.putStream(filePath, readableStream, options);
|
|
454
|
+
const accessUrl = this.generateAccessUrl(filePath);
|
|
455
|
+
const uploadTime = Date.now() - startTime;
|
|
456
|
+
logger.info("\u2705 [AliyunOSSProvider] \u6D41\u5F0F\u4E0A\u4F20\u5B8C\u6210: " + filePath + ", \u8017\u65F6: " + uploadTime + "ms");
|
|
457
|
+
return {
|
|
458
|
+
success: true,
|
|
459
|
+
path: filePath,
|
|
460
|
+
url: accessUrl,
|
|
461
|
+
size: contentLength,
|
|
462
|
+
data: {
|
|
463
|
+
name: result.name,
|
|
464
|
+
requestId: result.res?.rt || 0,
|
|
465
|
+
uploadTime,
|
|
466
|
+
ossUrl: result.url || result.name
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
} catch (error) {
|
|
470
|
+
logger.error("\u274C [AliyunOSSProvider] \u6D41\u5F0F\u4E0A\u4F20\u5931\u8D25: " + filePath + ":", error);
|
|
471
|
+
return {
|
|
472
|
+
success: false,
|
|
473
|
+
error: this.formatOSSError(error)
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* 批量删除文件
|
|
479
|
+
*/
|
|
480
|
+
async batchDelete(filePaths) {
|
|
481
|
+
this.ensureInitialized();
|
|
482
|
+
logger.info("\u{1F5D1}\uFE0F [AliyunOSSProvider] \u5F00\u59CB\u6279\u91CF\u5220\u9664\u6587\u4EF6\uFF0C\u6570\u91CF: " + filePaths.length);
|
|
483
|
+
try {
|
|
484
|
+
const result = await this.client?.deleteMulti(filePaths, {
|
|
485
|
+
quiet: false
|
|
486
|
+
// 返回删除结果
|
|
487
|
+
});
|
|
488
|
+
logger.info("\u2705 [AliyunOSSProvider] \u6279\u91CF\u5220\u9664\u5B8C\u6210\uFF0C\u6210\u529F: " + (result.deleted?.length || 0));
|
|
489
|
+
return {
|
|
490
|
+
success: true,
|
|
491
|
+
data: {
|
|
492
|
+
deleted: result.deleted,
|
|
493
|
+
requestId: result.res?.rt || 0
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
} catch (error) {
|
|
497
|
+
logger.error(`\u274C [AliyunOSSProvider] \u6279\u91CF\u5220\u9664\u5931\u8D25:`, error);
|
|
498
|
+
return {
|
|
499
|
+
success: false,
|
|
500
|
+
error: this.formatOSSError(error)
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* 复制文件
|
|
506
|
+
*/
|
|
507
|
+
async copy(sourcePath, targetPath) {
|
|
508
|
+
this.ensureInitialized();
|
|
509
|
+
logger.info("\u{1F4CB} [AliyunOSSProvider] \u5F00\u59CB\u590D\u5236\u6587\u4EF6: " + sourcePath + " -> " + targetPath);
|
|
510
|
+
try {
|
|
511
|
+
const result = await this.client?.copy(targetPath, sourcePath);
|
|
512
|
+
logger.info("\u2705 [AliyunOSSProvider] \u6587\u4EF6\u590D\u5236\u5B8C\u6210: " + sourcePath + " -> " + targetPath);
|
|
513
|
+
return {
|
|
514
|
+
success: true,
|
|
515
|
+
data: {
|
|
516
|
+
etag: result.data?.etag,
|
|
517
|
+
lastModified: result.data?.lastModified,
|
|
518
|
+
requestId: result.res?.rt || 0
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
} catch (error) {
|
|
522
|
+
logger.error("\u274C [AliyunOSSProvider] \u6587\u4EF6\u590D\u5236\u5931\u8D25: " + sourcePath + " -> " + targetPath + ":", error);
|
|
523
|
+
return {
|
|
524
|
+
success: false,
|
|
525
|
+
error: this.formatOSSError(error)
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* 编码元数据,避免中文字符在HTTP头部中的问题
|
|
531
|
+
*/
|
|
532
|
+
encodeMetadata(metadata) {
|
|
533
|
+
const encoded = {};
|
|
534
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
535
|
+
if (value !== null && value !== void 0) {
|
|
536
|
+
const stringValue = String(value);
|
|
537
|
+
encoded[key] = encodeURIComponent(stringValue);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return encoded;
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
export { AliyunOSSProvider };
|
|
545
|
+
//# sourceMappingURL=chunk-HDMIOOZY.mjs.map
|
|
546
|
+
//# sourceMappingURL=chunk-HDMIOOZY.mjs.map
|