@wecode-team/cms-supabase-api 0.1.34 → 0.1.35
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/README.md +77 -1
- package/USAGE_EXAMPLE.md +70 -3
- package/dist/handlers/upload.d.ts +25 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.esm.js +707 -56
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +712 -55
- package/dist/index.js.map +1 -1
- package/dist/services/oss-upload.service.d.ts +13 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/upload.d.ts +47 -0
- package/dist/utils/route-helpers.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1029,11 +1029,11 @@ function _defineProperty(e, r, t) {
|
|
|
1029
1029
|
}) : e[r] = t, e;
|
|
1030
1030
|
}
|
|
1031
1031
|
|
|
1032
|
-
function ownKeys$
|
|
1033
|
-
function _objectSpread$
|
|
1034
|
-
function _createForOfIteratorHelper$
|
|
1035
|
-
function _unsupportedIterableToArray$
|
|
1036
|
-
function _arrayLikeToArray$
|
|
1032
|
+
function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
1033
|
+
function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1034
|
+
function _createForOfIteratorHelper$3(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$4(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
1035
|
+
function _unsupportedIterableToArray$4(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$4(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$4(r, a) : void 0; } }
|
|
1036
|
+
function _arrayLikeToArray$4(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
1037
1037
|
// 字段类型映射到PostgreSQL类型
|
|
1038
1038
|
var fieldTypeMapping = {
|
|
1039
1039
|
string: "text",
|
|
@@ -1123,7 +1123,7 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1123
1123
|
value: function applySupabaseFilters(query, filters) {
|
|
1124
1124
|
if (!filters || filters.length === 0) return query;
|
|
1125
1125
|
var q = query;
|
|
1126
|
-
var _iterator = _createForOfIteratorHelper$
|
|
1126
|
+
var _iterator = _createForOfIteratorHelper$3(filters),
|
|
1127
1127
|
_step;
|
|
1128
1128
|
try {
|
|
1129
1129
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
@@ -2085,7 +2085,7 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
2085
2085
|
throw error;
|
|
2086
2086
|
case 2:
|
|
2087
2087
|
return _context14.abrupt("return", (data || []).map(function (item) {
|
|
2088
|
-
return _objectSpread$
|
|
2088
|
+
return _objectSpread$3({
|
|
2089
2089
|
id: item.id,
|
|
2090
2090
|
label: item[displayField] || "ID: ".concat(item.id)
|
|
2091
2091
|
}, item);
|
|
@@ -2198,8 +2198,8 @@ function getDynamicTableService() {
|
|
|
2198
2198
|
return defaultService$1;
|
|
2199
2199
|
}
|
|
2200
2200
|
|
|
2201
|
-
function ownKeys$
|
|
2202
|
-
function _objectSpread$
|
|
2201
|
+
function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2202
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2203
2203
|
var AuthService = /*#__PURE__*/function () {
|
|
2204
2204
|
function AuthService() {
|
|
2205
2205
|
_classCallCheck(this, AuthService);
|
|
@@ -2376,7 +2376,7 @@ var AuthService = /*#__PURE__*/function () {
|
|
|
2376
2376
|
return _regeneratorRuntime.wrap(function (_context4) {
|
|
2377
2377
|
while (1) switch (_context4.prev = _context4.next) {
|
|
2378
2378
|
case 0:
|
|
2379
|
-
finalUserData = _objectSpread$
|
|
2379
|
+
finalUserData = _objectSpread$2({
|
|
2380
2380
|
tableName: this.defaultTableName
|
|
2381
2381
|
}, userData);
|
|
2382
2382
|
_context4.prev = 1;
|
|
@@ -2434,7 +2434,7 @@ var AuthService = /*#__PURE__*/function () {
|
|
|
2434
2434
|
case 0:
|
|
2435
2435
|
updateData = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
|
|
2436
2436
|
// 设置默认值
|
|
2437
|
-
finalUpdateData = _objectSpread$
|
|
2437
|
+
finalUpdateData = _objectSpread$2({
|
|
2438
2438
|
tableName: this.defaultTableName
|
|
2439
2439
|
}, updateData);
|
|
2440
2440
|
_context5.prev = 1;
|
|
@@ -2706,6 +2706,519 @@ function getAuthService() {
|
|
|
2706
2706
|
return defaultService;
|
|
2707
2707
|
}
|
|
2708
2708
|
|
|
2709
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
2710
|
+
if (null == r) return {};
|
|
2711
|
+
var t = {};
|
|
2712
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
2713
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
2714
|
+
t[n] = r[n];
|
|
2715
|
+
}
|
|
2716
|
+
return t;
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
function _objectWithoutProperties(e, t) {
|
|
2720
|
+
if (null == e) return {};
|
|
2721
|
+
var o,
|
|
2722
|
+
r,
|
|
2723
|
+
i = _objectWithoutPropertiesLoose(e, t);
|
|
2724
|
+
if (Object.getOwnPropertySymbols) {
|
|
2725
|
+
var n = Object.getOwnPropertySymbols(e);
|
|
2726
|
+
for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
2727
|
+
}
|
|
2728
|
+
return i;
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
function _assertThisInitialized(e) {
|
|
2732
|
+
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
2733
|
+
return e;
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
function _possibleConstructorReturn(t, e) {
|
|
2737
|
+
if (e && ("object" == _typeof$1(e) || "function" == typeof e)) return e;
|
|
2738
|
+
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
2739
|
+
return _assertThisInitialized(t);
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2742
|
+
function _getPrototypeOf(t) {
|
|
2743
|
+
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
2744
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
2745
|
+
}, _getPrototypeOf(t);
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
function _setPrototypeOf(t, e) {
|
|
2749
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
2750
|
+
return t.__proto__ = e, t;
|
|
2751
|
+
}, _setPrototypeOf(t, e);
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
function _inherits(t, e) {
|
|
2755
|
+
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
|
|
2756
|
+
t.prototype = Object.create(e && e.prototype, {
|
|
2757
|
+
constructor: {
|
|
2758
|
+
value: t,
|
|
2759
|
+
writable: !0,
|
|
2760
|
+
configurable: !0
|
|
2761
|
+
}
|
|
2762
|
+
}), Object.defineProperty(t, "prototype", {
|
|
2763
|
+
writable: !1
|
|
2764
|
+
}), e && _setPrototypeOf(t, e);
|
|
2765
|
+
}
|
|
2766
|
+
|
|
2767
|
+
function _isNativeFunction(t) {
|
|
2768
|
+
try {
|
|
2769
|
+
return -1 !== Function.toString.call(t).indexOf("[native code]");
|
|
2770
|
+
} catch (n) {
|
|
2771
|
+
return "function" == typeof t;
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
function _isNativeReflectConstruct$1() {
|
|
2776
|
+
try {
|
|
2777
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
2778
|
+
} catch (t) {}
|
|
2779
|
+
return (_isNativeReflectConstruct$1 = function _isNativeReflectConstruct() {
|
|
2780
|
+
return !!t;
|
|
2781
|
+
})();
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
function _construct(t, e, r) {
|
|
2785
|
+
if (_isNativeReflectConstruct$1()) return Reflect.construct.apply(null, arguments);
|
|
2786
|
+
var o = [null];
|
|
2787
|
+
o.push.apply(o, e);
|
|
2788
|
+
var p = new (t.bind.apply(t, o))();
|
|
2789
|
+
return r && _setPrototypeOf(p, r.prototype), p;
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
function _wrapNativeSuper(t) {
|
|
2793
|
+
var r = "function" == typeof Map ? new Map() : void 0;
|
|
2794
|
+
return _wrapNativeSuper = function _wrapNativeSuper(t) {
|
|
2795
|
+
if (null === t || !_isNativeFunction(t)) return t;
|
|
2796
|
+
if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
|
|
2797
|
+
if (void 0 !== r) {
|
|
2798
|
+
if (r.has(t)) return r.get(t);
|
|
2799
|
+
r.set(t, Wrapper);
|
|
2800
|
+
}
|
|
2801
|
+
function Wrapper() {
|
|
2802
|
+
return _construct(t, arguments, _getPrototypeOf(this).constructor);
|
|
2803
|
+
}
|
|
2804
|
+
return Wrapper.prototype = Object.create(t.prototype, {
|
|
2805
|
+
constructor: {
|
|
2806
|
+
value: Wrapper,
|
|
2807
|
+
enumerable: !1,
|
|
2808
|
+
writable: !0,
|
|
2809
|
+
configurable: !0
|
|
2810
|
+
}
|
|
2811
|
+
}), _setPrototypeOf(Wrapper, t);
|
|
2812
|
+
}, _wrapNativeSuper(t);
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2815
|
+
var _excluded$1 = ["accessKeyId", "accessKeySecret"];
|
|
2816
|
+
function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2817
|
+
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2818
|
+
function _createForOfIteratorHelper$2(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$3(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
2819
|
+
function _unsupportedIterableToArray$3(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$3(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$3(r, a) : void 0; } }
|
|
2820
|
+
function _arrayLikeToArray$3(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
2821
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
2822
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
2823
|
+
var DEFAULT_MAX_SIZE = 2 * 1024 * 1024;
|
|
2824
|
+
var DEFAULT_SIGNED_URL_EXPIRES_IN = 60 * 60;
|
|
2825
|
+
var OssUploadError = /*#__PURE__*/function (_Error) {
|
|
2826
|
+
function OssUploadError(message) {
|
|
2827
|
+
var _this;
|
|
2828
|
+
var status = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 400;
|
|
2829
|
+
_classCallCheck(this, OssUploadError);
|
|
2830
|
+
_this = _callSuper(this, OssUploadError, [message]);
|
|
2831
|
+
_this.name = "OssUploadError";
|
|
2832
|
+
_this.status = status;
|
|
2833
|
+
return _this;
|
|
2834
|
+
}
|
|
2835
|
+
_inherits(OssUploadError, _Error);
|
|
2836
|
+
return _createClass(OssUploadError);
|
|
2837
|
+
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
2838
|
+
function requiredValue(value, name) {
|
|
2839
|
+
var trimmed = String(value || "").trim();
|
|
2840
|
+
if (!trimmed) {
|
|
2841
|
+
throw new OssUploadError("Missing required OSS config: ".concat(name), 500);
|
|
2842
|
+
}
|
|
2843
|
+
return trimmed;
|
|
2844
|
+
}
|
|
2845
|
+
function normalizeHost(value) {
|
|
2846
|
+
return value.replace(/^https?:\/\//, "").replace(/\/+$/, "");
|
|
2847
|
+
}
|
|
2848
|
+
function buildBucketBaseUrl(bucket, endpoint) {
|
|
2849
|
+
return "https://".concat(bucket, ".").concat(endpoint);
|
|
2850
|
+
}
|
|
2851
|
+
function normalizePublicBaseUrl(value, bucket, endpoint) {
|
|
2852
|
+
var raw = String(value || "").trim();
|
|
2853
|
+
if (!raw) {
|
|
2854
|
+
return buildBucketBaseUrl(bucket, endpoint);
|
|
2855
|
+
}
|
|
2856
|
+
var withProtocol = /^https?:\/\//i.test(raw) ? raw : "https://".concat(raw);
|
|
2857
|
+
try {
|
|
2858
|
+
var url = new URL(withProtocol);
|
|
2859
|
+
if (url.host === endpoint) {
|
|
2860
|
+
url.host = "".concat(bucket, ".").concat(endpoint);
|
|
2861
|
+
}
|
|
2862
|
+
return url.toString().replace(/\/+$/, "");
|
|
2863
|
+
} catch (_unused) {
|
|
2864
|
+
return withProtocol.replace(/\/+$/, "");
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
function sanitizePathSegment(value) {
|
|
2868
|
+
return String(value || "").trim().replace(/[^a-zA-Z0-9/_-]+/g, "-").replace(/\/{2,}/g, "/").replace(/^\/+|\/+$/g, "");
|
|
2869
|
+
}
|
|
2870
|
+
function extFromName() {
|
|
2871
|
+
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
2872
|
+
var match = String(name).match(/(\.[a-zA-Z0-9]+)$/);
|
|
2873
|
+
return match ? match[1].toLowerCase() : "";
|
|
2874
|
+
}
|
|
2875
|
+
function encodeObjectKey(objectKey) {
|
|
2876
|
+
return objectKey.split("/").map(function (segment) {
|
|
2877
|
+
return encodeURIComponent(segment);
|
|
2878
|
+
}).join("/");
|
|
2879
|
+
}
|
|
2880
|
+
function buildObjectKey(config, directory, originalName) {
|
|
2881
|
+
var safeDirectory = sanitizePathSegment(directory || "uploads");
|
|
2882
|
+
var safePrefix = sanitizePathSegment(config.prefix || "cms-assets");
|
|
2883
|
+
var extension = extFromName(originalName) || ".bin";
|
|
2884
|
+
var stamp = new Date().toISOString().replace(/[-:.TZ]/g, "").slice(0, 14);
|
|
2885
|
+
var random = Math.random().toString(16).slice(2, 10).padEnd(8, "0");
|
|
2886
|
+
return "".concat(safePrefix, "/").concat(safeDirectory, "/").concat(stamp, "-").concat(random).concat(extension);
|
|
2887
|
+
}
|
|
2888
|
+
function extractXmlField(errorText, fieldName) {
|
|
2889
|
+
var match = String(errorText || "").match(new RegExp("<".concat(fieldName, ">([^<]+)</").concat(fieldName, ">"), "i"));
|
|
2890
|
+
return match ? match[1].trim() : "";
|
|
2891
|
+
}
|
|
2892
|
+
function extractRecommendedEndpoint(errorText) {
|
|
2893
|
+
return normalizeHost(extractXmlField(errorText, "Endpoint"));
|
|
2894
|
+
}
|
|
2895
|
+
function resolvePublicBaseUrl(publicBaseUrl, bucket, endpoint, nextEndpoint) {
|
|
2896
|
+
var defaultBaseUrl = buildBucketBaseUrl(bucket, endpoint);
|
|
2897
|
+
if (publicBaseUrl === defaultBaseUrl) {
|
|
2898
|
+
return buildBucketBaseUrl(bucket, nextEndpoint);
|
|
2899
|
+
}
|
|
2900
|
+
return publicBaseUrl;
|
|
2901
|
+
}
|
|
2902
|
+
function arrayBufferToBase64(value) {
|
|
2903
|
+
var bytes = new Uint8Array(value);
|
|
2904
|
+
if (typeof Buffer !== "undefined") {
|
|
2905
|
+
return Buffer.from(bytes).toString("base64");
|
|
2906
|
+
}
|
|
2907
|
+
var binary = "";
|
|
2908
|
+
var _iterator = _createForOfIteratorHelper$2(bytes),
|
|
2909
|
+
_step;
|
|
2910
|
+
try {
|
|
2911
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2912
|
+
var _byte = _step.value;
|
|
2913
|
+
binary += String.fromCharCode(_byte);
|
|
2914
|
+
}
|
|
2915
|
+
} catch (err) {
|
|
2916
|
+
_iterator.e(err);
|
|
2917
|
+
} finally {
|
|
2918
|
+
_iterator.f();
|
|
2919
|
+
}
|
|
2920
|
+
return btoa(binary);
|
|
2921
|
+
}
|
|
2922
|
+
function signBase64(_x, _x2) {
|
|
2923
|
+
return _signBase.apply(this, arguments);
|
|
2924
|
+
}
|
|
2925
|
+
function _signBase() {
|
|
2926
|
+
_signBase = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(secret, stringToSign) {
|
|
2927
|
+
var _globalThis$crypto;
|
|
2928
|
+
var encoder, key, signature;
|
|
2929
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
2930
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
2931
|
+
case 0:
|
|
2932
|
+
if ((_globalThis$crypto = globalThis.crypto) !== null && _globalThis$crypto !== void 0 && _globalThis$crypto.subtle) {
|
|
2933
|
+
_context2.next = 1;
|
|
2934
|
+
break;
|
|
2935
|
+
}
|
|
2936
|
+
throw new OssUploadError("Web Crypto is unavailable in the current runtime", 500);
|
|
2937
|
+
case 1:
|
|
2938
|
+
encoder = new TextEncoder();
|
|
2939
|
+
_context2.next = 2;
|
|
2940
|
+
return globalThis.crypto.subtle.importKey("raw", encoder.encode(secret), {
|
|
2941
|
+
name: "HMAC",
|
|
2942
|
+
hash: "SHA-1"
|
|
2943
|
+
}, false, ["sign"]);
|
|
2944
|
+
case 2:
|
|
2945
|
+
key = _context2.sent;
|
|
2946
|
+
_context2.next = 3;
|
|
2947
|
+
return globalThis.crypto.subtle.sign("HMAC", key, encoder.encode(stringToSign));
|
|
2948
|
+
case 3:
|
|
2949
|
+
signature = _context2.sent;
|
|
2950
|
+
return _context2.abrupt("return", arrayBufferToBase64(signature));
|
|
2951
|
+
case 4:
|
|
2952
|
+
case "end":
|
|
2953
|
+
return _context2.stop();
|
|
2954
|
+
}
|
|
2955
|
+
}, _callee2);
|
|
2956
|
+
}));
|
|
2957
|
+
return _signBase.apply(this, arguments);
|
|
2958
|
+
}
|
|
2959
|
+
function createPermissionDeniedMessage(bucket, objectKey, errorText) {
|
|
2960
|
+
var action = extractXmlField(errorText, "AuthAction");
|
|
2961
|
+
var principalType = extractXmlField(errorText, "AuthPrincipalType");
|
|
2962
|
+
var principalName = extractXmlField(errorText, "AuthPrincipalDisplayName");
|
|
2963
|
+
var policyType = extractXmlField(errorText, "PolicyType");
|
|
2964
|
+
var denyType = extractXmlField(errorText, "NoPermissionType");
|
|
2965
|
+
var parts = ["OSS permission denied for bucket \"".concat(bucket, "\""), action ? "missing ".concat(action) : "missing required OSS permission", "resource ".concat(bucket, "/").concat(objectKey)];
|
|
2966
|
+
if (principalType || principalName) {
|
|
2967
|
+
parts.push("principal ".concat([principalType, principalName].filter(Boolean).join(":")));
|
|
2968
|
+
}
|
|
2969
|
+
if (policyType || denyType) {
|
|
2970
|
+
parts.push("policy ".concat([policyType, denyType].filter(Boolean).join("/")));
|
|
2971
|
+
}
|
|
2972
|
+
parts.push("Grant oss:PutObject to the configured RAM user for this bucket or prefix.");
|
|
2973
|
+
return parts.join("; ");
|
|
2974
|
+
}
|
|
2975
|
+
function createEndpointMismatchMessage(bucket, endpoint, suggestedEndpoint) {
|
|
2976
|
+
return ["OSS endpoint mismatch for bucket \"".concat(bucket, "\""), "configured OSS_ENDPOINT=".concat(endpoint), "OSS says use ".concat(suggestedEndpoint), "Update OSS_ENDPOINT and OSS_PUBLIC_BASE_URL to the bucket's actual region."].join("; ");
|
|
2977
|
+
}
|
|
2978
|
+
function createAuthorization(_x3, _x4, _x5, _x6, _x7) {
|
|
2979
|
+
return _createAuthorization.apply(this, arguments);
|
|
2980
|
+
}
|
|
2981
|
+
function _createAuthorization() {
|
|
2982
|
+
_createAuthorization = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(config, method, objectKey, contentType, date) {
|
|
2983
|
+
var stringToSign, signature;
|
|
2984
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
2985
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
2986
|
+
case 0:
|
|
2987
|
+
stringToSign = [method, "", contentType, date, "/".concat(config.bucket, "/").concat(objectKey)].join("\n");
|
|
2988
|
+
_context3.next = 1;
|
|
2989
|
+
return signBase64(config.accessKeySecret, stringToSign);
|
|
2990
|
+
case 1:
|
|
2991
|
+
signature = _context3.sent;
|
|
2992
|
+
return _context3.abrupt("return", "OSS ".concat(config.accessKeyId, ":").concat(signature));
|
|
2993
|
+
case 2:
|
|
2994
|
+
case "end":
|
|
2995
|
+
return _context3.stop();
|
|
2996
|
+
}
|
|
2997
|
+
}, _callee3);
|
|
2998
|
+
}));
|
|
2999
|
+
return _createAuthorization.apply(this, arguments);
|
|
3000
|
+
}
|
|
3001
|
+
function createSignedGetUrl(_x8, _x9, _x0) {
|
|
3002
|
+
return _createSignedGetUrl.apply(this, arguments);
|
|
3003
|
+
}
|
|
3004
|
+
function _createSignedGetUrl() {
|
|
3005
|
+
_createSignedGetUrl = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(config, objectKey, expiresIn) {
|
|
3006
|
+
var expires, stringToSign, signature, encodedObjectKey, url;
|
|
3007
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
3008
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
3009
|
+
case 0:
|
|
3010
|
+
expires = Math.max(1, Math.floor(Date.now() / 1000) + expiresIn);
|
|
3011
|
+
stringToSign = ["GET", "", "", String(expires), "/".concat(config.bucket, "/").concat(objectKey)].join("\n");
|
|
3012
|
+
_context4.next = 1;
|
|
3013
|
+
return signBase64(config.accessKeySecret, stringToSign);
|
|
3014
|
+
case 1:
|
|
3015
|
+
signature = _context4.sent;
|
|
3016
|
+
encodedObjectKey = encodeObjectKey(objectKey);
|
|
3017
|
+
url = new URL("".concat(buildBucketBaseUrl(config.bucket, config.endpoint), "/").concat(encodedObjectKey));
|
|
3018
|
+
url.searchParams.set("OSSAccessKeyId", config.accessKeyId);
|
|
3019
|
+
url.searchParams.set("Expires", String(expires));
|
|
3020
|
+
url.searchParams.set("Signature", signature);
|
|
3021
|
+
return _context4.abrupt("return", url.toString());
|
|
3022
|
+
case 2:
|
|
3023
|
+
case "end":
|
|
3024
|
+
return _context4.stop();
|
|
3025
|
+
}
|
|
3026
|
+
}, _callee4);
|
|
3027
|
+
}));
|
|
3028
|
+
return _createSignedGetUrl.apply(this, arguments);
|
|
3029
|
+
}
|
|
3030
|
+
function putObjectToOss(_x1, _x10, _x11, _x12, _x13) {
|
|
3031
|
+
return _putObjectToOss.apply(this, arguments);
|
|
3032
|
+
}
|
|
3033
|
+
function _putObjectToOss() {
|
|
3034
|
+
_putObjectToOss = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(config, endpoint, objectKey, contentType, buffer) {
|
|
3035
|
+
var date, authorization, bodyBytes, body;
|
|
3036
|
+
return _regeneratorRuntime.wrap(function (_context5) {
|
|
3037
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
3038
|
+
case 0:
|
|
3039
|
+
date = new Date().toUTCString();
|
|
3040
|
+
_context5.next = 1;
|
|
3041
|
+
return createAuthorization(config, "PUT", objectKey, contentType, date);
|
|
3042
|
+
case 1:
|
|
3043
|
+
authorization = _context5.sent;
|
|
3044
|
+
bodyBytes = Uint8Array.from(buffer);
|
|
3045
|
+
body = new Blob([bodyBytes], {
|
|
3046
|
+
type: contentType
|
|
3047
|
+
});
|
|
3048
|
+
return _context5.abrupt("return", fetch("".concat(buildBucketBaseUrl(config.bucket, endpoint), "/").concat(encodeObjectKey(objectKey)), {
|
|
3049
|
+
method: "PUT",
|
|
3050
|
+
headers: {
|
|
3051
|
+
Authorization: authorization,
|
|
3052
|
+
Date: date,
|
|
3053
|
+
"Content-Type": contentType
|
|
3054
|
+
},
|
|
3055
|
+
body: body
|
|
3056
|
+
}));
|
|
3057
|
+
case 2:
|
|
3058
|
+
case "end":
|
|
3059
|
+
return _context5.stop();
|
|
3060
|
+
}
|
|
3061
|
+
}, _callee5);
|
|
3062
|
+
}));
|
|
3063
|
+
return _putObjectToOss.apply(this, arguments);
|
|
3064
|
+
}
|
|
3065
|
+
function normalizeConfig(config) {
|
|
3066
|
+
var bucket = requiredValue(config.bucket, "bucket");
|
|
3067
|
+
var endpoint = normalizeHost(requiredValue(config.endpoint, "endpoint"));
|
|
3068
|
+
return {
|
|
3069
|
+
provider: "aliyun-oss",
|
|
3070
|
+
bucket: bucket,
|
|
3071
|
+
endpoint: endpoint,
|
|
3072
|
+
accessKeyId: requiredValue(config.accessKeyId, "accessKeyId"),
|
|
3073
|
+
accessKeySecret: requiredValue(config.accessKeySecret, "accessKeySecret"),
|
|
3074
|
+
publicBaseUrl: normalizePublicBaseUrl(config.publicBaseUrl, bucket, endpoint),
|
|
3075
|
+
prefix: sanitizePathSegment(config.prefix || "cms-assets"),
|
|
3076
|
+
maxSize: Number(config.maxSize || DEFAULT_MAX_SIZE),
|
|
3077
|
+
returnMode: config.returnMode || "both",
|
|
3078
|
+
signedUrlExpiresIn: Number(config.signedUrlExpiresIn || DEFAULT_SIGNED_URL_EXPIRES_IN)
|
|
3079
|
+
};
|
|
3080
|
+
}
|
|
3081
|
+
var OssUploadService = /*#__PURE__*/function () {
|
|
3082
|
+
function OssUploadService(config) {
|
|
3083
|
+
_classCallCheck(this, OssUploadService);
|
|
3084
|
+
this.config = normalizeConfig(config);
|
|
3085
|
+
}
|
|
3086
|
+
return _createClass(OssUploadService, [{
|
|
3087
|
+
key: "getConfig",
|
|
3088
|
+
value: function getConfig() {
|
|
3089
|
+
var _this$config = this.config;
|
|
3090
|
+
_this$config.accessKeyId;
|
|
3091
|
+
_this$config.accessKeySecret;
|
|
3092
|
+
var safeConfig = _objectWithoutProperties(_this$config, _excluded$1);
|
|
3093
|
+
return safeConfig;
|
|
3094
|
+
}
|
|
3095
|
+
}, {
|
|
3096
|
+
key: "upload",
|
|
3097
|
+
value: function () {
|
|
3098
|
+
var _upload = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(input) {
|
|
3099
|
+
var contentType, buffer, objectKey, activeEndpoint, publicBaseUrl, response, lastErrorText, errorText, suggestedEndpoint, finalErrorText, finalSuggestedEndpoint, encodedObjectKey, publicUrl, signedUrl, _t;
|
|
3100
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
3101
|
+
while (1) switch (_context.prev = _context.next) {
|
|
3102
|
+
case 0:
|
|
3103
|
+
contentType = String(input.contentType || "application/octet-stream").trim() || "application/octet-stream";
|
|
3104
|
+
buffer = new Uint8Array(input.buffer);
|
|
3105
|
+
if (buffer.byteLength) {
|
|
3106
|
+
_context.next = 1;
|
|
3107
|
+
break;
|
|
3108
|
+
}
|
|
3109
|
+
throw new OssUploadError("Uploaded file is empty");
|
|
3110
|
+
case 1:
|
|
3111
|
+
if (!(buffer.byteLength > this.config.maxSize)) {
|
|
3112
|
+
_context.next = 2;
|
|
3113
|
+
break;
|
|
3114
|
+
}
|
|
3115
|
+
throw new OssUploadError("File exceeds max size of ".concat(this.config.maxSize, " bytes"));
|
|
3116
|
+
case 2:
|
|
3117
|
+
objectKey = buildObjectKey(this.config, input.directory, input.originalName);
|
|
3118
|
+
activeEndpoint = this.config.endpoint;
|
|
3119
|
+
publicBaseUrl = this.config.publicBaseUrl;
|
|
3120
|
+
_context.next = 3;
|
|
3121
|
+
return putObjectToOss(this.config, activeEndpoint, objectKey, contentType, buffer);
|
|
3122
|
+
case 3:
|
|
3123
|
+
response = _context.sent;
|
|
3124
|
+
lastErrorText = "";
|
|
3125
|
+
if (response.ok) {
|
|
3126
|
+
_context.next = 10;
|
|
3127
|
+
break;
|
|
3128
|
+
}
|
|
3129
|
+
_context.next = 4;
|
|
3130
|
+
return response.text();
|
|
3131
|
+
case 4:
|
|
3132
|
+
errorText = _context.sent;
|
|
3133
|
+
lastErrorText = errorText;
|
|
3134
|
+
suggestedEndpoint = extractRecommendedEndpoint(errorText);
|
|
3135
|
+
if (!(response.status === 403 && suggestedEndpoint && suggestedEndpoint !== activeEndpoint)) {
|
|
3136
|
+
_context.next = 7;
|
|
3137
|
+
break;
|
|
3138
|
+
}
|
|
3139
|
+
activeEndpoint = suggestedEndpoint;
|
|
3140
|
+
publicBaseUrl = resolvePublicBaseUrl(publicBaseUrl, this.config.bucket, this.config.endpoint, suggestedEndpoint);
|
|
3141
|
+
_context.next = 5;
|
|
3142
|
+
return putObjectToOss(this.config, activeEndpoint, objectKey, contentType, buffer);
|
|
3143
|
+
case 5:
|
|
3144
|
+
response = _context.sent;
|
|
3145
|
+
if (response.ok) {
|
|
3146
|
+
_context.next = 7;
|
|
3147
|
+
break;
|
|
3148
|
+
}
|
|
3149
|
+
_context.next = 6;
|
|
3150
|
+
return response.text();
|
|
3151
|
+
case 6:
|
|
3152
|
+
lastErrorText = _context.sent;
|
|
3153
|
+
case 7:
|
|
3154
|
+
if (response.ok) {
|
|
3155
|
+
_context.next = 10;
|
|
3156
|
+
break;
|
|
3157
|
+
}
|
|
3158
|
+
finalErrorText = lastErrorText;
|
|
3159
|
+
finalSuggestedEndpoint = extractRecommendedEndpoint(finalErrorText);
|
|
3160
|
+
if (!(response.status === 403 && finalSuggestedEndpoint && finalSuggestedEndpoint !== this.config.endpoint)) {
|
|
3161
|
+
_context.next = 8;
|
|
3162
|
+
break;
|
|
3163
|
+
}
|
|
3164
|
+
throw new OssUploadError(createEndpointMismatchMessage(this.config.bucket, this.config.endpoint, finalSuggestedEndpoint), 400);
|
|
3165
|
+
case 8:
|
|
3166
|
+
if (!(response.status === 403 && /<Code>AccessDenied<\/Code>/i.test(finalErrorText))) {
|
|
3167
|
+
_context.next = 9;
|
|
3168
|
+
break;
|
|
3169
|
+
}
|
|
3170
|
+
throw new OssUploadError(createPermissionDeniedMessage(this.config.bucket, objectKey, finalErrorText), 403);
|
|
3171
|
+
case 9:
|
|
3172
|
+
throw new OssUploadError("OSS upload failed: ".concat(response.status, " ").concat(finalErrorText), 502);
|
|
3173
|
+
case 10:
|
|
3174
|
+
encodedObjectKey = encodeObjectKey(objectKey);
|
|
3175
|
+
publicUrl = "".concat(publicBaseUrl, "/").concat(encodedObjectKey);
|
|
3176
|
+
if (!(this.config.returnMode === "public-url")) {
|
|
3177
|
+
_context.next = 11;
|
|
3178
|
+
break;
|
|
3179
|
+
}
|
|
3180
|
+
_t = undefined;
|
|
3181
|
+
_context.next = 13;
|
|
3182
|
+
break;
|
|
3183
|
+
case 11:
|
|
3184
|
+
_context.next = 12;
|
|
3185
|
+
return createSignedGetUrl(_objectSpread$1(_objectSpread$1({}, this.config), {}, {
|
|
3186
|
+
endpoint: activeEndpoint
|
|
3187
|
+
}), objectKey, this.config.signedUrlExpiresIn);
|
|
3188
|
+
case 12:
|
|
3189
|
+
_t = _context.sent;
|
|
3190
|
+
case 13:
|
|
3191
|
+
signedUrl = _t;
|
|
3192
|
+
return _context.abrupt("return", {
|
|
3193
|
+
objectKey: objectKey,
|
|
3194
|
+
url: this.config.returnMode === "signed-url" ? signedUrl || publicUrl : publicUrl,
|
|
3195
|
+
signedUrl: this.config.returnMode === "both" || this.config.returnMode === "signed-url" ? signedUrl : undefined
|
|
3196
|
+
});
|
|
3197
|
+
case 14:
|
|
3198
|
+
case "end":
|
|
3199
|
+
return _context.stop();
|
|
3200
|
+
}
|
|
3201
|
+
}, _callee, this);
|
|
3202
|
+
}));
|
|
3203
|
+
function upload(_x14) {
|
|
3204
|
+
return _upload.apply(this, arguments);
|
|
3205
|
+
}
|
|
3206
|
+
return upload;
|
|
3207
|
+
}()
|
|
3208
|
+
}]);
|
|
3209
|
+
}();
|
|
3210
|
+
var ossUploadService = null;
|
|
3211
|
+
function initializeOssUpload(config) {
|
|
3212
|
+
ossUploadService = new OssUploadService(config);
|
|
3213
|
+
return ossUploadService;
|
|
3214
|
+
}
|
|
3215
|
+
function getOssUploadService() {
|
|
3216
|
+
if (!ossUploadService) {
|
|
3217
|
+
throw new OssUploadError("OSS upload is not initialized. Call initializeOssUpload(config) before registering upload routes.", 500);
|
|
3218
|
+
}
|
|
3219
|
+
return ossUploadService;
|
|
3220
|
+
}
|
|
3221
|
+
|
|
2709
3222
|
var ADMIN_REGISTRY_TABLE = "_cms_admin_registry";
|
|
2710
3223
|
var ensured = false;
|
|
2711
3224
|
function normalizeSessionId(sessionId) {
|
|
@@ -2830,10 +3343,15 @@ function _isUserSessionAdmin() {
|
|
|
2830
3343
|
return _isUserSessionAdmin.apply(this, arguments);
|
|
2831
3344
|
}
|
|
2832
3345
|
|
|
3346
|
+
function _createForOfIteratorHelper$1(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$2(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
3347
|
+
function _unsupportedIterableToArray$2(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$2(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$2(r, a) : void 0; } }
|
|
3348
|
+
function _arrayLikeToArray$2(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
3349
|
+
var RESERVED_STATUS_FIELD = "status";
|
|
3350
|
+
var PUBLISH_STATUS_VALUES = new Set(["draft", "published"]);
|
|
2833
3351
|
// 初始化Supabase连接和CMS系统
|
|
2834
3352
|
function initializeSystem() {
|
|
2835
3353
|
return _initializeSystem.apply(this, arguments);
|
|
2836
|
-
}
|
|
3354
|
+
}
|
|
2837
3355
|
function _initializeSystem() {
|
|
2838
3356
|
_initializeSystem = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
2839
3357
|
var _t;
|
|
@@ -2864,6 +3382,65 @@ function _initializeSystem() {
|
|
|
2864
3382
|
}));
|
|
2865
3383
|
return _initializeSystem.apply(this, arguments);
|
|
2866
3384
|
}
|
|
3385
|
+
function validateReservedFields(jsonSchema) {
|
|
3386
|
+
if (!(jsonSchema !== null && jsonSchema !== void 0 && jsonSchema.fields) || !Array.isArray(jsonSchema.fields)) {
|
|
3387
|
+
return "json_schema 必须包含 fields 数组";
|
|
3388
|
+
}
|
|
3389
|
+
var _iterator = _createForOfIteratorHelper$1(jsonSchema.fields),
|
|
3390
|
+
_step;
|
|
3391
|
+
try {
|
|
3392
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
3393
|
+
var field = _step.value;
|
|
3394
|
+
if ((field === null || field === void 0 ? void 0 : field.name) !== RESERVED_STATUS_FIELD) {
|
|
3395
|
+
continue;
|
|
3396
|
+
}
|
|
3397
|
+
if (field.type !== "string") {
|
|
3398
|
+
return '字段 "status" 是保留字段,类型必须为 string。若这是业务状态,请改名为 category_status、order_status 等更具体的字段名。';
|
|
3399
|
+
}
|
|
3400
|
+
var configuredValues = new Set();
|
|
3401
|
+
if (field.defaultValue !== undefined && field.defaultValue !== null) {
|
|
3402
|
+
configuredValues.add(String(field.defaultValue));
|
|
3403
|
+
}
|
|
3404
|
+
if (Array.isArray(field["enum"])) {
|
|
3405
|
+
var _iterator2 = _createForOfIteratorHelper$1(field["enum"]),
|
|
3406
|
+
_step2;
|
|
3407
|
+
try {
|
|
3408
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
3409
|
+
var enumValue = _step2.value;
|
|
3410
|
+
configuredValues.add(String(enumValue));
|
|
3411
|
+
}
|
|
3412
|
+
} catch (err) {
|
|
3413
|
+
_iterator2.e(err);
|
|
3414
|
+
} finally {
|
|
3415
|
+
_iterator2.f();
|
|
3416
|
+
}
|
|
3417
|
+
}
|
|
3418
|
+
if (configuredValues.size === 0) {
|
|
3419
|
+
return '字段 "status" 是保留发布状态字段。请显式将其配置为 draft/published;如果你需要业务状态,请改名为 category_status、order_status、user_status 等。';
|
|
3420
|
+
}
|
|
3421
|
+
var _iterator3 = _createForOfIteratorHelper$1(configuredValues),
|
|
3422
|
+
_step3;
|
|
3423
|
+
try {
|
|
3424
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
3425
|
+
var value = _step3.value;
|
|
3426
|
+
if (!PUBLISH_STATUS_VALUES.has(value)) {
|
|
3427
|
+
return "\u5B57\u6BB5 \"status\" \u4EC5\u5141\u8BB8\u8868\u793A\u53D1\u5E03\u72B6\u6001\uFF0C\u652F\u6301\u7684\u503C\u53EA\u6709 draft/published\u3002\u68C0\u6D4B\u5230\u975E\u6CD5\u503C \"".concat(value, "\"\u3002\u5982\u679C\u8FD9\u662F\u4E1A\u52A1\u72B6\u6001\uFF0C\u8BF7\u6539\u540D\u4E3A category_status\u3001order_status\u3001user_status \u7B49\u3002");
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3430
|
+
} catch (err) {
|
|
3431
|
+
_iterator3.e(err);
|
|
3432
|
+
} finally {
|
|
3433
|
+
_iterator3.f();
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
} catch (err) {
|
|
3437
|
+
_iterator.e(err);
|
|
3438
|
+
} finally {
|
|
3439
|
+
_iterator.f();
|
|
3440
|
+
}
|
|
3441
|
+
return null;
|
|
3442
|
+
}
|
|
3443
|
+
// GET - 获取所有模型
|
|
2867
3444
|
function getModels(_x) {
|
|
2868
3445
|
return _getModels.apply(this, arguments);
|
|
2869
3446
|
}
|
|
@@ -2941,7 +3518,7 @@ function createModel(_x2) {
|
|
|
2941
3518
|
// PUT - 更新模型
|
|
2942
3519
|
function _createModel() {
|
|
2943
3520
|
_createModel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(c) {
|
|
2944
|
-
var cmsModelService, dynamicTableService, body, name, table_name, json_schema, _response2, _response3, existingModel, _response4, allModels, nameExists, _response5, tableExists, _response6, tableCreated, _response7, newModel, response, _response8, _t3;
|
|
3521
|
+
var cmsModelService, dynamicTableService, body, name, table_name, json_schema, _response2, schemaValidationError, _response3, existingModel, _response4, allModels, nameExists, _response5, tableExists, _response6, tableCreated, _response7, newModel, response, _response8, _t3;
|
|
2945
3522
|
return _regeneratorRuntime.wrap(function (_context3) {
|
|
2946
3523
|
while (1) switch (_context3.prev = _context3.next) {
|
|
2947
3524
|
case 0:
|
|
@@ -2966,13 +3543,15 @@ function _createModel() {
|
|
|
2966
3543
|
};
|
|
2967
3544
|
return _context3.abrupt("return", c.json(_response2, 200));
|
|
2968
3545
|
case 3:
|
|
2969
|
-
|
|
3546
|
+
// 验证 JSON 模式格式和保留字段规则
|
|
3547
|
+
schemaValidationError = validateReservedFields(json_schema);
|
|
3548
|
+
if (!schemaValidationError) {
|
|
2970
3549
|
_context3.next = 4;
|
|
2971
3550
|
break;
|
|
2972
3551
|
}
|
|
2973
3552
|
_response3 = {
|
|
2974
3553
|
success: false,
|
|
2975
|
-
message:
|
|
3554
|
+
message: schemaValidationError
|
|
2976
3555
|
};
|
|
2977
3556
|
return _context3.abrupt("return", c.json(_response3, 200));
|
|
2978
3557
|
case 4:
|
|
@@ -3073,7 +3652,7 @@ function updateModel(_x3) {
|
|
|
3073
3652
|
// DELETE - 删除模型
|
|
3074
3653
|
function _updateModel() {
|
|
3075
3654
|
_updateModel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(c) {
|
|
3076
|
-
var cmsModelService, body, id, name, json_schema, _response9, model, _response0, updateData, updatedModel, response,
|
|
3655
|
+
var cmsModelService, body, id, name, json_schema, _response9, model, _response0, schemaValidationError, _response1, updateData, updatedModel, response, _response10, _t4;
|
|
3077
3656
|
return _regeneratorRuntime.wrap(function (_context4) {
|
|
3078
3657
|
while (1) switch (_context4.prev = _context4.next) {
|
|
3079
3658
|
case 0:
|
|
@@ -3111,13 +3690,28 @@ function _updateModel() {
|
|
|
3111
3690
|
};
|
|
3112
3691
|
return _context4.abrupt("return", c.json(_response0, 200));
|
|
3113
3692
|
case 5:
|
|
3693
|
+
if (!json_schema) {
|
|
3694
|
+
_context4.next = 6;
|
|
3695
|
+
break;
|
|
3696
|
+
}
|
|
3697
|
+
schemaValidationError = validateReservedFields(json_schema);
|
|
3698
|
+
if (!schemaValidationError) {
|
|
3699
|
+
_context4.next = 6;
|
|
3700
|
+
break;
|
|
3701
|
+
}
|
|
3702
|
+
_response1 = {
|
|
3703
|
+
success: false,
|
|
3704
|
+
message: schemaValidationError
|
|
3705
|
+
};
|
|
3706
|
+
return _context4.abrupt("return", c.json(_response1, 200));
|
|
3707
|
+
case 6:
|
|
3114
3708
|
// 更新模型信息(不允许修改表名)
|
|
3115
3709
|
updateData = {};
|
|
3116
3710
|
if (name) updateData.name = name;
|
|
3117
3711
|
if (json_schema) updateData.json_schema = json_schema;
|
|
3118
|
-
_context4.next =
|
|
3712
|
+
_context4.next = 7;
|
|
3119
3713
|
return cmsModelService.update(id, updateData);
|
|
3120
|
-
case
|
|
3714
|
+
case 7:
|
|
3121
3715
|
updatedModel = _context4.sent;
|
|
3122
3716
|
response = {
|
|
3123
3717
|
success: true,
|
|
@@ -3125,21 +3719,21 @@ function _updateModel() {
|
|
|
3125
3719
|
data: updatedModel
|
|
3126
3720
|
};
|
|
3127
3721
|
return _context4.abrupt("return", c.json(response));
|
|
3128
|
-
case
|
|
3129
|
-
_context4.prev =
|
|
3722
|
+
case 8:
|
|
3723
|
+
_context4.prev = 8;
|
|
3130
3724
|
_t4 = _context4["catch"](0);
|
|
3131
3725
|
console.error("更新模型失败:", _t4);
|
|
3132
|
-
|
|
3726
|
+
_response10 = {
|
|
3133
3727
|
success: false,
|
|
3134
3728
|
message: "更新模型失败",
|
|
3135
3729
|
error: _t4 instanceof Error ? _t4.message : "未知错误"
|
|
3136
3730
|
};
|
|
3137
|
-
return _context4.abrupt("return", c.json(
|
|
3138
|
-
case
|
|
3731
|
+
return _context4.abrupt("return", c.json(_response10, 500));
|
|
3732
|
+
case 9:
|
|
3139
3733
|
case "end":
|
|
3140
3734
|
return _context4.stop();
|
|
3141
3735
|
}
|
|
3142
|
-
}, _callee4, null, [[0,
|
|
3736
|
+
}, _callee4, null, [[0, 8]]);
|
|
3143
3737
|
}));
|
|
3144
3738
|
return _updateModel.apply(this, arguments);
|
|
3145
3739
|
}
|
|
@@ -3148,7 +3742,7 @@ function deleteModel(_x4) {
|
|
|
3148
3742
|
}
|
|
3149
3743
|
function _deleteModel() {
|
|
3150
3744
|
_deleteModel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(c) {
|
|
3151
|
-
var cmsModelService, dynamicTableService, idStr,
|
|
3745
|
+
var cmsModelService, dynamicTableService, idStr, _response11, id, model, _response12, tableDropped, _response13, response, _response14, _t5;
|
|
3152
3746
|
return _regeneratorRuntime.wrap(function (_context5) {
|
|
3153
3747
|
while (1) switch (_context5.prev = _context5.next) {
|
|
3154
3748
|
case 0:
|
|
@@ -3163,11 +3757,11 @@ function _deleteModel() {
|
|
|
3163
3757
|
_context5.next = 2;
|
|
3164
3758
|
break;
|
|
3165
3759
|
}
|
|
3166
|
-
|
|
3760
|
+
_response11 = {
|
|
3167
3761
|
success: false,
|
|
3168
3762
|
message: "缺少模型 ID"
|
|
3169
3763
|
};
|
|
3170
|
-
return _context5.abrupt("return", c.json(
|
|
3764
|
+
return _context5.abrupt("return", c.json(_response11, 200));
|
|
3171
3765
|
case 2:
|
|
3172
3766
|
id = parseInt(idStr);
|
|
3173
3767
|
_context5.next = 3;
|
|
@@ -3178,11 +3772,11 @@ function _deleteModel() {
|
|
|
3178
3772
|
_context5.next = 4;
|
|
3179
3773
|
break;
|
|
3180
3774
|
}
|
|
3181
|
-
|
|
3775
|
+
_response12 = {
|
|
3182
3776
|
success: false,
|
|
3183
3777
|
message: "模型不存在"
|
|
3184
3778
|
};
|
|
3185
|
-
return _context5.abrupt("return", c.json(
|
|
3779
|
+
return _context5.abrupt("return", c.json(_response12, 200));
|
|
3186
3780
|
case 4:
|
|
3187
3781
|
_context5.next = 5;
|
|
3188
3782
|
return dynamicTableService.dropTable(model.table_name);
|
|
@@ -3192,11 +3786,11 @@ function _deleteModel() {
|
|
|
3192
3786
|
_context5.next = 6;
|
|
3193
3787
|
break;
|
|
3194
3788
|
}
|
|
3195
|
-
|
|
3789
|
+
_response13 = {
|
|
3196
3790
|
success: false,
|
|
3197
3791
|
message: "删除数据表失败"
|
|
3198
3792
|
};
|
|
3199
|
-
return _context5.abrupt("return", c.json(
|
|
3793
|
+
return _context5.abrupt("return", c.json(_response13, 200));
|
|
3200
3794
|
case 6:
|
|
3201
3795
|
_context5.next = 7;
|
|
3202
3796
|
return cmsModelService["delete"](id);
|
|
@@ -3210,12 +3804,12 @@ function _deleteModel() {
|
|
|
3210
3804
|
_context5.prev = 8;
|
|
3211
3805
|
_t5 = _context5["catch"](0);
|
|
3212
3806
|
console.error("删除模型失败:", _t5);
|
|
3213
|
-
|
|
3807
|
+
_response14 = {
|
|
3214
3808
|
success: false,
|
|
3215
3809
|
message: "删除模型失败",
|
|
3216
3810
|
error: _t5 instanceof Error ? _t5.message : "未知错误"
|
|
3217
3811
|
};
|
|
3218
|
-
return _context5.abrupt("return", c.json(
|
|
3812
|
+
return _context5.abrupt("return", c.json(_response14, 500));
|
|
3219
3813
|
case 9:
|
|
3220
3814
|
case "end":
|
|
3221
3815
|
return _context5.stop();
|
|
@@ -3225,28 +3819,6 @@ function _deleteModel() {
|
|
|
3225
3819
|
return _deleteModel.apply(this, arguments);
|
|
3226
3820
|
}
|
|
3227
3821
|
|
|
3228
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
3229
|
-
if (null == r) return {};
|
|
3230
|
-
var t = {};
|
|
3231
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
3232
|
-
if (-1 !== e.indexOf(n)) continue;
|
|
3233
|
-
t[n] = r[n];
|
|
3234
|
-
}
|
|
3235
|
-
return t;
|
|
3236
|
-
}
|
|
3237
|
-
|
|
3238
|
-
function _objectWithoutProperties(e, t) {
|
|
3239
|
-
if (null == e) return {};
|
|
3240
|
-
var o,
|
|
3241
|
-
r,
|
|
3242
|
-
i = _objectWithoutPropertiesLoose(e, t);
|
|
3243
|
-
if (Object.getOwnPropertySymbols) {
|
|
3244
|
-
var n = Object.getOwnPropertySymbols(e);
|
|
3245
|
-
for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
3246
|
-
}
|
|
3247
|
-
return i;
|
|
3248
|
-
}
|
|
3249
|
-
|
|
3250
3822
|
function _arrayWithHoles(r) {
|
|
3251
3823
|
if (Array.isArray(r)) return r;
|
|
3252
3824
|
}
|
|
@@ -4968,6 +5540,81 @@ function requireAuth(handler) {
|
|
|
4968
5540
|
}();
|
|
4969
5541
|
}
|
|
4970
5542
|
|
|
5543
|
+
function readTextField(formData, fieldName) {
|
|
5544
|
+
var value = formData.get(fieldName);
|
|
5545
|
+
return typeof value === "string" ? value.trim() : "";
|
|
5546
|
+
}
|
|
5547
|
+
function isFileLike(value) {
|
|
5548
|
+
return !!value && typeof value !== "string" && typeof value.arrayBuffer === "function";
|
|
5549
|
+
}
|
|
5550
|
+
function uploadToOss(_x) {
|
|
5551
|
+
return _uploadToOss.apply(this, arguments);
|
|
5552
|
+
}
|
|
5553
|
+
function _uploadToOss() {
|
|
5554
|
+
_uploadToOss = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(c) {
|
|
5555
|
+
var formData, file, uploadService, result, status, _t, _t2, _t3, _t4, _t5, _t6;
|
|
5556
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
5557
|
+
while (1) switch (_context.prev = _context.next) {
|
|
5558
|
+
case 0:
|
|
5559
|
+
_context.prev = 0;
|
|
5560
|
+
_context.next = 1;
|
|
5561
|
+
return c.req.raw.formData();
|
|
5562
|
+
case 1:
|
|
5563
|
+
formData = _context.sent;
|
|
5564
|
+
file = formData.get("file");
|
|
5565
|
+
if (isFileLike(file)) {
|
|
5566
|
+
_context.next = 2;
|
|
5567
|
+
break;
|
|
5568
|
+
}
|
|
5569
|
+
return _context.abrupt("return", c.json({
|
|
5570
|
+
success: false,
|
|
5571
|
+
message: "Missing file in multipart request"
|
|
5572
|
+
}, 400));
|
|
5573
|
+
case 2:
|
|
5574
|
+
uploadService = getOssUploadService();
|
|
5575
|
+
_t = uploadService;
|
|
5576
|
+
_context.next = 3;
|
|
5577
|
+
return file.arrayBuffer();
|
|
5578
|
+
case 3:
|
|
5579
|
+
_t2 = _context.sent;
|
|
5580
|
+
_t3 = file.type || "application/octet-stream";
|
|
5581
|
+
_t4 = readTextField(formData, "directory");
|
|
5582
|
+
_t5 = file.name || "upload.bin";
|
|
5583
|
+
_context.next = 4;
|
|
5584
|
+
return _t.upload.call(_t, {
|
|
5585
|
+
buffer: _t2,
|
|
5586
|
+
contentType: _t3,
|
|
5587
|
+
directory: _t4,
|
|
5588
|
+
originalName: _t5
|
|
5589
|
+
});
|
|
5590
|
+
case 4:
|
|
5591
|
+
result = _context.sent;
|
|
5592
|
+
return _context.abrupt("return", c.json({
|
|
5593
|
+
success: true,
|
|
5594
|
+
url: result.url,
|
|
5595
|
+
signedUrl: result.signedUrl,
|
|
5596
|
+
objectKey: result.objectKey,
|
|
5597
|
+
fieldName: readTextField(formData, "fieldName"),
|
|
5598
|
+
tableName: readTextField(formData, "tableName")
|
|
5599
|
+
}, 200));
|
|
5600
|
+
case 5:
|
|
5601
|
+
_context.prev = 5;
|
|
5602
|
+
_t6 = _context["catch"](0);
|
|
5603
|
+
status = _t6 instanceof OssUploadError ? _t6.status : 500;
|
|
5604
|
+
return _context.abrupt("return", c.json({
|
|
5605
|
+
success: false,
|
|
5606
|
+
message: "Upload failed",
|
|
5607
|
+
error: _t6 instanceof Error ? _t6.message : "Unknown upload error"
|
|
5608
|
+
}, status));
|
|
5609
|
+
case 6:
|
|
5610
|
+
case "end":
|
|
5611
|
+
return _context.stop();
|
|
5612
|
+
}
|
|
5613
|
+
}, _callee, null, [[0, 5]]);
|
|
5614
|
+
}));
|
|
5615
|
+
return _uploadToOss.apply(this, arguments);
|
|
5616
|
+
}
|
|
5617
|
+
|
|
4971
5618
|
function getRoleFromSupabaseUser$1(user) {
|
|
4972
5619
|
var _user$app_metadata, _user$user_metadata;
|
|
4973
5620
|
var appRole = user === null || user === void 0 || (_user$app_metadata = user.app_metadata) === null || _user$app_metadata === void 0 ? void 0 : _user$app_metadata.role;
|
|
@@ -5448,6 +6095,10 @@ function createAuthRoute(app, tableName) {
|
|
|
5448
6095
|
});
|
|
5449
6096
|
return app;
|
|
5450
6097
|
}
|
|
6098
|
+
function createOssUploadRoute(app) {
|
|
6099
|
+
app.post("/upload", requireJwtAuth, requireAdminRole, uploadToOss);
|
|
6100
|
+
return app;
|
|
6101
|
+
}
|
|
5451
6102
|
// 一键创建所有CMS路由
|
|
5452
6103
|
function createCmsRoutes(app) {
|
|
5453
6104
|
createModelRoute(app);
|
|
@@ -5460,6 +6111,8 @@ exports.AuthService = AuthService;
|
|
|
5460
6111
|
exports.CmsModel = getCmsModelService;
|
|
5461
6112
|
exports.CmsModelService = CmsModelService;
|
|
5462
6113
|
exports.DynamicTableService = DynamicTableService;
|
|
6114
|
+
exports.OssUploadError = OssUploadError;
|
|
6115
|
+
exports.OssUploadService = OssUploadService;
|
|
5463
6116
|
exports.closeDatabase = closeSupabase;
|
|
5464
6117
|
exports.closeSupabase = closeSupabase;
|
|
5465
6118
|
exports.createAuthRoute = createAuthRoute;
|
|
@@ -5469,6 +6122,7 @@ exports.createDynamicAuthRoute = createDynamicAuthRoute;
|
|
|
5469
6122
|
exports.createDynamicDataRoute = createDynamicDataRoute;
|
|
5470
6123
|
exports.createModel = createModel;
|
|
5471
6124
|
exports.createModelRoute = createModelRoute;
|
|
6125
|
+
exports.createOssUploadRoute = createOssUploadRoute;
|
|
5472
6126
|
exports.createTableData = createTableData;
|
|
5473
6127
|
exports.deleteModel = deleteModel;
|
|
5474
6128
|
exports.deleteTableData = deleteTableData;
|
|
@@ -5480,6 +6134,7 @@ exports.getCurrentUser = getCurrentUser;
|
|
|
5480
6134
|
exports.getDatabase = getSupabase;
|
|
5481
6135
|
exports.getDynamicTableService = getDynamicTableService;
|
|
5482
6136
|
exports.getModels = getModels;
|
|
6137
|
+
exports.getOssUploadService = getOssUploadService;
|
|
5483
6138
|
exports.getRelationOptions = getRelationOptions;
|
|
5484
6139
|
exports.getSupabase = getSupabase;
|
|
5485
6140
|
exports.getSupabaseSetupSQL = getSupabaseSetupSQL;
|
|
@@ -5488,6 +6143,7 @@ exports.getTableDataWithRelations = getTableDataWithRelations;
|
|
|
5488
6143
|
exports.initializeCmsModel = initializeCmsModel;
|
|
5489
6144
|
exports.initializeCmsSystem = initializeCmsSystem;
|
|
5490
6145
|
exports.initializeDatabase = initializeSupabase;
|
|
6146
|
+
exports.initializeOssUpload = initializeOssUpload;
|
|
5491
6147
|
exports.initializeSupabase = initializeSupabase;
|
|
5492
6148
|
exports.login = login;
|
|
5493
6149
|
exports.requireAuth = requireAuth;
|
|
@@ -5497,5 +6153,6 @@ exports.syncDatabase = initializeCmsSystem;
|
|
|
5497
6153
|
exports.testConnection = testConnection;
|
|
5498
6154
|
exports.updateModel = updateModel;
|
|
5499
6155
|
exports.updateTableData = updateTableData;
|
|
6156
|
+
exports.uploadToOss = uploadToOss;
|
|
5500
6157
|
exports.verifyAuth = verifyAuth;
|
|
5501
6158
|
//# sourceMappingURL=index.js.map
|