@wecode-team/cms-supabase-api 0.1.33 → 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 +841 -182
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +846 -181
- 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,10 +2706,652 @@ 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
|
+
|
|
3222
|
+
var ADMIN_REGISTRY_TABLE = "_cms_admin_registry";
|
|
3223
|
+
var ensured = false;
|
|
3224
|
+
function normalizeSessionId(sessionId) {
|
|
3225
|
+
// 统一将连字符转换为下划线,确保 UUID 格式一致性
|
|
3226
|
+
// 例如:1047aab4-eecb-4538-ad8d-b5847e762f30 和 1047aab4_eecb_4538_ad8d_b5847e762f30 被视为相同
|
|
3227
|
+
return (sessionId || "").trim().replace(/-/g, "_");
|
|
3228
|
+
}
|
|
3229
|
+
/**
|
|
3230
|
+
* 从前端传来的 auth tableName 中提取 session_id
|
|
3231
|
+
* 约定:auth tableName 形如 `${sessionId}_cms_users`;无前缀则为 `cms_users`
|
|
3232
|
+
*/
|
|
3233
|
+
function extractSessionIdFromAuthTableName(tableName) {
|
|
3234
|
+
var name = (tableName || "").trim();
|
|
3235
|
+
if (!name) return "";
|
|
3236
|
+
if (name === "cms_users") return "";
|
|
3237
|
+
if (name.endsWith("_cms_users")) return name.slice(0, -"_cms_users".length);
|
|
3238
|
+
// 兼容:如果传入的不是 cms_users,也允许把最后一个 "_cms_users" 前缀当作 session
|
|
3239
|
+
var idx = name.lastIndexOf("_cms_users");
|
|
3240
|
+
if (idx > 0) return name.slice(0, idx);
|
|
3241
|
+
return "";
|
|
3242
|
+
}
|
|
3243
|
+
function ensureAdminRegistryTable(_x) {
|
|
3244
|
+
return _ensureAdminRegistryTable.apply(this, arguments);
|
|
3245
|
+
}
|
|
3246
|
+
function _ensureAdminRegistryTable() {
|
|
3247
|
+
_ensureAdminRegistryTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(supabase) {
|
|
3248
|
+
var _yield$supabase$from$, error;
|
|
3249
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
3250
|
+
while (1) switch (_context.prev = _context.next) {
|
|
3251
|
+
case 0:
|
|
3252
|
+
if (!ensured) {
|
|
3253
|
+
_context.next = 1;
|
|
3254
|
+
break;
|
|
3255
|
+
}
|
|
3256
|
+
return _context.abrupt("return", true);
|
|
3257
|
+
case 1:
|
|
3258
|
+
_context.prev = 1;
|
|
3259
|
+
_context.next = 2;
|
|
3260
|
+
return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id").limit(1);
|
|
3261
|
+
case 2:
|
|
3262
|
+
_yield$supabase$from$ = _context.sent;
|
|
3263
|
+
error = _yield$supabase$from$.error;
|
|
3264
|
+
if (error) {
|
|
3265
|
+
_context.next = 3;
|
|
3266
|
+
break;
|
|
3267
|
+
}
|
|
3268
|
+
ensured = true;
|
|
3269
|
+
return _context.abrupt("return", true);
|
|
3270
|
+
case 3:
|
|
3271
|
+
_context.next = 5;
|
|
3272
|
+
break;
|
|
3273
|
+
case 4:
|
|
3274
|
+
_context.prev = 4;
|
|
3275
|
+
_context["catch"](1);
|
|
3276
|
+
case 5:
|
|
3277
|
+
return _context.abrupt("return", false);
|
|
3278
|
+
case 6:
|
|
3279
|
+
case "end":
|
|
3280
|
+
return _context.stop();
|
|
3281
|
+
}
|
|
3282
|
+
}, _callee, null, [[1, 4]]);
|
|
3283
|
+
}));
|
|
3284
|
+
return _ensureAdminRegistryTable.apply(this, arguments);
|
|
3285
|
+
}
|
|
3286
|
+
function getSessionAdminRow(_x2, _x3) {
|
|
3287
|
+
return _getSessionAdminRow.apply(this, arguments);
|
|
3288
|
+
}
|
|
3289
|
+
function _getSessionAdminRow() {
|
|
3290
|
+
_getSessionAdminRow = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(supabase, sessionId) {
|
|
3291
|
+
var sid, _yield$supabase$from$2, data, error;
|
|
3292
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
3293
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
3294
|
+
case 0:
|
|
3295
|
+
sid = normalizeSessionId(sessionId);
|
|
3296
|
+
_context2.next = 1;
|
|
3297
|
+
return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id,user_id,email").eq("session_id", sid).maybeSingle();
|
|
3298
|
+
case 1:
|
|
3299
|
+
_yield$supabase$from$2 = _context2.sent;
|
|
3300
|
+
data = _yield$supabase$from$2.data;
|
|
3301
|
+
error = _yield$supabase$from$2.error;
|
|
3302
|
+
if (!(error || !data)) {
|
|
3303
|
+
_context2.next = 2;
|
|
3304
|
+
break;
|
|
3305
|
+
}
|
|
3306
|
+
return _context2.abrupt("return", null);
|
|
3307
|
+
case 2:
|
|
3308
|
+
return _context2.abrupt("return", data);
|
|
3309
|
+
case 3:
|
|
3310
|
+
case "end":
|
|
3311
|
+
return _context2.stop();
|
|
3312
|
+
}
|
|
3313
|
+
}, _callee2);
|
|
3314
|
+
}));
|
|
3315
|
+
return _getSessionAdminRow.apply(this, arguments);
|
|
3316
|
+
}
|
|
3317
|
+
function isUserSessionAdmin(_x4, _x5, _x6) {
|
|
3318
|
+
return _isUserSessionAdmin.apply(this, arguments);
|
|
3319
|
+
}
|
|
3320
|
+
function _isUserSessionAdmin() {
|
|
3321
|
+
_isUserSessionAdmin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(supabase, sessionId, userId) {
|
|
3322
|
+
var row;
|
|
3323
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
3324
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
3325
|
+
case 0:
|
|
3326
|
+
_context3.next = 1;
|
|
3327
|
+
return getSessionAdminRow(supabase, sessionId);
|
|
3328
|
+
case 1:
|
|
3329
|
+
row = _context3.sent;
|
|
3330
|
+
if (row) {
|
|
3331
|
+
_context3.next = 2;
|
|
3332
|
+
break;
|
|
3333
|
+
}
|
|
3334
|
+
return _context3.abrupt("return", false);
|
|
3335
|
+
case 2:
|
|
3336
|
+
return _context3.abrupt("return", row.user_id === userId);
|
|
3337
|
+
case 3:
|
|
3338
|
+
case "end":
|
|
3339
|
+
return _context3.stop();
|
|
3340
|
+
}
|
|
3341
|
+
}, _callee3);
|
|
3342
|
+
}));
|
|
3343
|
+
return _isUserSessionAdmin.apply(this, arguments);
|
|
3344
|
+
}
|
|
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"]);
|
|
2709
3351
|
// 初始化Supabase连接和CMS系统
|
|
2710
3352
|
function initializeSystem() {
|
|
2711
3353
|
return _initializeSystem.apply(this, arguments);
|
|
2712
|
-
}
|
|
3354
|
+
}
|
|
2713
3355
|
function _initializeSystem() {
|
|
2714
3356
|
_initializeSystem = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
2715
3357
|
var _t;
|
|
@@ -2740,13 +3382,72 @@ function _initializeSystem() {
|
|
|
2740
3382
|
}));
|
|
2741
3383
|
return _initializeSystem.apply(this, arguments);
|
|
2742
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 - 获取所有模型
|
|
2743
3444
|
function getModels(_x) {
|
|
2744
3445
|
return _getModels.apply(this, arguments);
|
|
2745
3446
|
}
|
|
2746
3447
|
// POST - 创建新模型
|
|
2747
3448
|
function _getModels() {
|
|
2748
3449
|
_getModels = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
|
|
2749
|
-
var cmsModelService, page, limit, name, models, total, offset, paginatedModels, response, _response, _t2;
|
|
3450
|
+
var cmsModelService, page, limit, name, sessionId, models, tablePrefix, total, offset, paginatedModels, response, _response, _t2;
|
|
2750
3451
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
2751
3452
|
while (1) switch (_context2.prev = _context2.next) {
|
|
2752
3453
|
case 0:
|
|
@@ -2757,11 +3458,19 @@ function _getModels() {
|
|
|
2757
3458
|
cmsModelService = getCmsModelService();
|
|
2758
3459
|
page = parseInt(c.req.query("page") || "1");
|
|
2759
3460
|
limit = parseInt(c.req.query("limit") || "10");
|
|
2760
|
-
name = c.req.query("name"); //
|
|
3461
|
+
name = c.req.query("name"); // 获取当前请求的 session_id
|
|
3462
|
+
sessionId = normalizeSessionId(c.req.header("X-Session-Id") || c.req.header("x-session-id")); // 获取所有模型
|
|
2761
3463
|
_context2.next = 2;
|
|
2762
3464
|
return cmsModelService.findAll();
|
|
2763
3465
|
case 2:
|
|
2764
3466
|
models = _context2.sent;
|
|
3467
|
+
// 根据 session_id 过滤模型(只返回属于当前 session 的表)
|
|
3468
|
+
if (sessionId) {
|
|
3469
|
+
tablePrefix = sessionId + "_";
|
|
3470
|
+
models = models.filter(function (model) {
|
|
3471
|
+
return model.table_name.startsWith(tablePrefix);
|
|
3472
|
+
});
|
|
3473
|
+
}
|
|
2765
3474
|
// 如果有名称过滤
|
|
2766
3475
|
if (name) {
|
|
2767
3476
|
models = models.filter(function (model) {
|
|
@@ -2809,7 +3518,7 @@ function createModel(_x2) {
|
|
|
2809
3518
|
// PUT - 更新模型
|
|
2810
3519
|
function _createModel() {
|
|
2811
3520
|
_createModel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(c) {
|
|
2812
|
-
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;
|
|
2813
3522
|
return _regeneratorRuntime.wrap(function (_context3) {
|
|
2814
3523
|
while (1) switch (_context3.prev = _context3.next) {
|
|
2815
3524
|
case 0:
|
|
@@ -2834,13 +3543,15 @@ function _createModel() {
|
|
|
2834
3543
|
};
|
|
2835
3544
|
return _context3.abrupt("return", c.json(_response2, 200));
|
|
2836
3545
|
case 3:
|
|
2837
|
-
|
|
3546
|
+
// 验证 JSON 模式格式和保留字段规则
|
|
3547
|
+
schemaValidationError = validateReservedFields(json_schema);
|
|
3548
|
+
if (!schemaValidationError) {
|
|
2838
3549
|
_context3.next = 4;
|
|
2839
3550
|
break;
|
|
2840
3551
|
}
|
|
2841
3552
|
_response3 = {
|
|
2842
3553
|
success: false,
|
|
2843
|
-
message:
|
|
3554
|
+
message: schemaValidationError
|
|
2844
3555
|
};
|
|
2845
3556
|
return _context3.abrupt("return", c.json(_response3, 200));
|
|
2846
3557
|
case 4:
|
|
@@ -2941,7 +3652,7 @@ function updateModel(_x3) {
|
|
|
2941
3652
|
// DELETE - 删除模型
|
|
2942
3653
|
function _updateModel() {
|
|
2943
3654
|
_updateModel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(c) {
|
|
2944
|
-
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;
|
|
2945
3656
|
return _regeneratorRuntime.wrap(function (_context4) {
|
|
2946
3657
|
while (1) switch (_context4.prev = _context4.next) {
|
|
2947
3658
|
case 0:
|
|
@@ -2979,13 +3690,28 @@ function _updateModel() {
|
|
|
2979
3690
|
};
|
|
2980
3691
|
return _context4.abrupt("return", c.json(_response0, 200));
|
|
2981
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:
|
|
2982
3708
|
// 更新模型信息(不允许修改表名)
|
|
2983
3709
|
updateData = {};
|
|
2984
3710
|
if (name) updateData.name = name;
|
|
2985
3711
|
if (json_schema) updateData.json_schema = json_schema;
|
|
2986
|
-
_context4.next =
|
|
3712
|
+
_context4.next = 7;
|
|
2987
3713
|
return cmsModelService.update(id, updateData);
|
|
2988
|
-
case
|
|
3714
|
+
case 7:
|
|
2989
3715
|
updatedModel = _context4.sent;
|
|
2990
3716
|
response = {
|
|
2991
3717
|
success: true,
|
|
@@ -2993,21 +3719,21 @@ function _updateModel() {
|
|
|
2993
3719
|
data: updatedModel
|
|
2994
3720
|
};
|
|
2995
3721
|
return _context4.abrupt("return", c.json(response));
|
|
2996
|
-
case
|
|
2997
|
-
_context4.prev =
|
|
3722
|
+
case 8:
|
|
3723
|
+
_context4.prev = 8;
|
|
2998
3724
|
_t4 = _context4["catch"](0);
|
|
2999
3725
|
console.error("更新模型失败:", _t4);
|
|
3000
|
-
|
|
3726
|
+
_response10 = {
|
|
3001
3727
|
success: false,
|
|
3002
3728
|
message: "更新模型失败",
|
|
3003
3729
|
error: _t4 instanceof Error ? _t4.message : "未知错误"
|
|
3004
3730
|
};
|
|
3005
|
-
return _context4.abrupt("return", c.json(
|
|
3006
|
-
case
|
|
3731
|
+
return _context4.abrupt("return", c.json(_response10, 500));
|
|
3732
|
+
case 9:
|
|
3007
3733
|
case "end":
|
|
3008
3734
|
return _context4.stop();
|
|
3009
3735
|
}
|
|
3010
|
-
}, _callee4, null, [[0,
|
|
3736
|
+
}, _callee4, null, [[0, 8]]);
|
|
3011
3737
|
}));
|
|
3012
3738
|
return _updateModel.apply(this, arguments);
|
|
3013
3739
|
}
|
|
@@ -3016,7 +3742,7 @@ function deleteModel(_x4) {
|
|
|
3016
3742
|
}
|
|
3017
3743
|
function _deleteModel() {
|
|
3018
3744
|
_deleteModel = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(c) {
|
|
3019
|
-
var cmsModelService, dynamicTableService, idStr,
|
|
3745
|
+
var cmsModelService, dynamicTableService, idStr, _response11, id, model, _response12, tableDropped, _response13, response, _response14, _t5;
|
|
3020
3746
|
return _regeneratorRuntime.wrap(function (_context5) {
|
|
3021
3747
|
while (1) switch (_context5.prev = _context5.next) {
|
|
3022
3748
|
case 0:
|
|
@@ -3031,11 +3757,11 @@ function _deleteModel() {
|
|
|
3031
3757
|
_context5.next = 2;
|
|
3032
3758
|
break;
|
|
3033
3759
|
}
|
|
3034
|
-
|
|
3760
|
+
_response11 = {
|
|
3035
3761
|
success: false,
|
|
3036
3762
|
message: "缺少模型 ID"
|
|
3037
3763
|
};
|
|
3038
|
-
return _context5.abrupt("return", c.json(
|
|
3764
|
+
return _context5.abrupt("return", c.json(_response11, 200));
|
|
3039
3765
|
case 2:
|
|
3040
3766
|
id = parseInt(idStr);
|
|
3041
3767
|
_context5.next = 3;
|
|
@@ -3046,11 +3772,11 @@ function _deleteModel() {
|
|
|
3046
3772
|
_context5.next = 4;
|
|
3047
3773
|
break;
|
|
3048
3774
|
}
|
|
3049
|
-
|
|
3775
|
+
_response12 = {
|
|
3050
3776
|
success: false,
|
|
3051
3777
|
message: "模型不存在"
|
|
3052
3778
|
};
|
|
3053
|
-
return _context5.abrupt("return", c.json(
|
|
3779
|
+
return _context5.abrupt("return", c.json(_response12, 200));
|
|
3054
3780
|
case 4:
|
|
3055
3781
|
_context5.next = 5;
|
|
3056
3782
|
return dynamicTableService.dropTable(model.table_name);
|
|
@@ -3060,11 +3786,11 @@ function _deleteModel() {
|
|
|
3060
3786
|
_context5.next = 6;
|
|
3061
3787
|
break;
|
|
3062
3788
|
}
|
|
3063
|
-
|
|
3789
|
+
_response13 = {
|
|
3064
3790
|
success: false,
|
|
3065
3791
|
message: "删除数据表失败"
|
|
3066
3792
|
};
|
|
3067
|
-
return _context5.abrupt("return", c.json(
|
|
3793
|
+
return _context5.abrupt("return", c.json(_response13, 200));
|
|
3068
3794
|
case 6:
|
|
3069
3795
|
_context5.next = 7;
|
|
3070
3796
|
return cmsModelService["delete"](id);
|
|
@@ -3078,12 +3804,12 @@ function _deleteModel() {
|
|
|
3078
3804
|
_context5.prev = 8;
|
|
3079
3805
|
_t5 = _context5["catch"](0);
|
|
3080
3806
|
console.error("删除模型失败:", _t5);
|
|
3081
|
-
|
|
3807
|
+
_response14 = {
|
|
3082
3808
|
success: false,
|
|
3083
3809
|
message: "删除模型失败",
|
|
3084
3810
|
error: _t5 instanceof Error ? _t5.message : "未知错误"
|
|
3085
3811
|
};
|
|
3086
|
-
return _context5.abrupt("return", c.json(
|
|
3812
|
+
return _context5.abrupt("return", c.json(_response14, 500));
|
|
3087
3813
|
case 9:
|
|
3088
3814
|
case "end":
|
|
3089
3815
|
return _context5.stop();
|
|
@@ -3093,28 +3819,6 @@ function _deleteModel() {
|
|
|
3093
3819
|
return _deleteModel.apply(this, arguments);
|
|
3094
3820
|
}
|
|
3095
3821
|
|
|
3096
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
3097
|
-
if (null == r) return {};
|
|
3098
|
-
var t = {};
|
|
3099
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
3100
|
-
if (-1 !== e.indexOf(n)) continue;
|
|
3101
|
-
t[n] = r[n];
|
|
3102
|
-
}
|
|
3103
|
-
return t;
|
|
3104
|
-
}
|
|
3105
|
-
|
|
3106
|
-
function _objectWithoutProperties(e, t) {
|
|
3107
|
-
if (null == e) return {};
|
|
3108
|
-
var o,
|
|
3109
|
-
r,
|
|
3110
|
-
i = _objectWithoutPropertiesLoose(e, t);
|
|
3111
|
-
if (Object.getOwnPropertySymbols) {
|
|
3112
|
-
var n = Object.getOwnPropertySymbols(e);
|
|
3113
|
-
for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
3114
|
-
}
|
|
3115
|
-
return i;
|
|
3116
|
-
}
|
|
3117
|
-
|
|
3118
3822
|
function _arrayWithHoles(r) {
|
|
3119
3823
|
if (Array.isArray(r)) return r;
|
|
3120
3824
|
}
|
|
@@ -4221,130 +4925,6 @@ var AuthUtils = /*#__PURE__*/function () {
|
|
|
4221
4925
|
}]);
|
|
4222
4926
|
}();
|
|
4223
4927
|
|
|
4224
|
-
var ADMIN_REGISTRY_TABLE = "_cms_admin_registry";
|
|
4225
|
-
var ensured = false;
|
|
4226
|
-
function normalizeSessionId(sessionId) {
|
|
4227
|
-
// 统一将连字符转换为下划线,确保 UUID 格式一致性
|
|
4228
|
-
// 例如:1047aab4-eecb-4538-ad8d-b5847e762f30 和 1047aab4_eecb_4538_ad8d_b5847e762f30 被视为相同
|
|
4229
|
-
return (sessionId || "").trim().replace(/-/g, "_");
|
|
4230
|
-
}
|
|
4231
|
-
/**
|
|
4232
|
-
* 从前端传来的 auth tableName 中提取 session_id
|
|
4233
|
-
* 约定:auth tableName 形如 `${sessionId}_cms_users`;无前缀则为 `cms_users`
|
|
4234
|
-
*/
|
|
4235
|
-
function extractSessionIdFromAuthTableName(tableName) {
|
|
4236
|
-
var name = (tableName || "").trim();
|
|
4237
|
-
if (!name) return "";
|
|
4238
|
-
if (name === "cms_users") return "";
|
|
4239
|
-
if (name.endsWith("_cms_users")) return name.slice(0, -"_cms_users".length);
|
|
4240
|
-
// 兼容:如果传入的不是 cms_users,也允许把最后一个 "_cms_users" 前缀当作 session
|
|
4241
|
-
var idx = name.lastIndexOf("_cms_users");
|
|
4242
|
-
if (idx > 0) return name.slice(0, idx);
|
|
4243
|
-
return "";
|
|
4244
|
-
}
|
|
4245
|
-
function ensureAdminRegistryTable(_x) {
|
|
4246
|
-
return _ensureAdminRegistryTable.apply(this, arguments);
|
|
4247
|
-
}
|
|
4248
|
-
function _ensureAdminRegistryTable() {
|
|
4249
|
-
_ensureAdminRegistryTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(supabase) {
|
|
4250
|
-
var _yield$supabase$from$, error;
|
|
4251
|
-
return _regeneratorRuntime.wrap(function (_context) {
|
|
4252
|
-
while (1) switch (_context.prev = _context.next) {
|
|
4253
|
-
case 0:
|
|
4254
|
-
if (!ensured) {
|
|
4255
|
-
_context.next = 1;
|
|
4256
|
-
break;
|
|
4257
|
-
}
|
|
4258
|
-
return _context.abrupt("return", true);
|
|
4259
|
-
case 1:
|
|
4260
|
-
_context.prev = 1;
|
|
4261
|
-
_context.next = 2;
|
|
4262
|
-
return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id").limit(1);
|
|
4263
|
-
case 2:
|
|
4264
|
-
_yield$supabase$from$ = _context.sent;
|
|
4265
|
-
error = _yield$supabase$from$.error;
|
|
4266
|
-
if (error) {
|
|
4267
|
-
_context.next = 3;
|
|
4268
|
-
break;
|
|
4269
|
-
}
|
|
4270
|
-
ensured = true;
|
|
4271
|
-
return _context.abrupt("return", true);
|
|
4272
|
-
case 3:
|
|
4273
|
-
_context.next = 5;
|
|
4274
|
-
break;
|
|
4275
|
-
case 4:
|
|
4276
|
-
_context.prev = 4;
|
|
4277
|
-
_context["catch"](1);
|
|
4278
|
-
case 5:
|
|
4279
|
-
return _context.abrupt("return", false);
|
|
4280
|
-
case 6:
|
|
4281
|
-
case "end":
|
|
4282
|
-
return _context.stop();
|
|
4283
|
-
}
|
|
4284
|
-
}, _callee, null, [[1, 4]]);
|
|
4285
|
-
}));
|
|
4286
|
-
return _ensureAdminRegistryTable.apply(this, arguments);
|
|
4287
|
-
}
|
|
4288
|
-
function getSessionAdminRow(_x2, _x3) {
|
|
4289
|
-
return _getSessionAdminRow.apply(this, arguments);
|
|
4290
|
-
}
|
|
4291
|
-
function _getSessionAdminRow() {
|
|
4292
|
-
_getSessionAdminRow = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(supabase, sessionId) {
|
|
4293
|
-
var sid, _yield$supabase$from$2, data, error;
|
|
4294
|
-
return _regeneratorRuntime.wrap(function (_context2) {
|
|
4295
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
4296
|
-
case 0:
|
|
4297
|
-
sid = normalizeSessionId(sessionId);
|
|
4298
|
-
_context2.next = 1;
|
|
4299
|
-
return supabase.from(ADMIN_REGISTRY_TABLE).select("session_id,user_id,email").eq("session_id", sid).maybeSingle();
|
|
4300
|
-
case 1:
|
|
4301
|
-
_yield$supabase$from$2 = _context2.sent;
|
|
4302
|
-
data = _yield$supabase$from$2.data;
|
|
4303
|
-
error = _yield$supabase$from$2.error;
|
|
4304
|
-
if (!(error || !data)) {
|
|
4305
|
-
_context2.next = 2;
|
|
4306
|
-
break;
|
|
4307
|
-
}
|
|
4308
|
-
return _context2.abrupt("return", null);
|
|
4309
|
-
case 2:
|
|
4310
|
-
return _context2.abrupt("return", data);
|
|
4311
|
-
case 3:
|
|
4312
|
-
case "end":
|
|
4313
|
-
return _context2.stop();
|
|
4314
|
-
}
|
|
4315
|
-
}, _callee2);
|
|
4316
|
-
}));
|
|
4317
|
-
return _getSessionAdminRow.apply(this, arguments);
|
|
4318
|
-
}
|
|
4319
|
-
function isUserSessionAdmin(_x4, _x5, _x6) {
|
|
4320
|
-
return _isUserSessionAdmin.apply(this, arguments);
|
|
4321
|
-
}
|
|
4322
|
-
function _isUserSessionAdmin() {
|
|
4323
|
-
_isUserSessionAdmin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(supabase, sessionId, userId) {
|
|
4324
|
-
var row;
|
|
4325
|
-
return _regeneratorRuntime.wrap(function (_context3) {
|
|
4326
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
4327
|
-
case 0:
|
|
4328
|
-
_context3.next = 1;
|
|
4329
|
-
return getSessionAdminRow(supabase, sessionId);
|
|
4330
|
-
case 1:
|
|
4331
|
-
row = _context3.sent;
|
|
4332
|
-
if (row) {
|
|
4333
|
-
_context3.next = 2;
|
|
4334
|
-
break;
|
|
4335
|
-
}
|
|
4336
|
-
return _context3.abrupt("return", false);
|
|
4337
|
-
case 2:
|
|
4338
|
-
return _context3.abrupt("return", row.user_id === userId);
|
|
4339
|
-
case 3:
|
|
4340
|
-
case "end":
|
|
4341
|
-
return _context3.stop();
|
|
4342
|
-
}
|
|
4343
|
-
}, _callee3);
|
|
4344
|
-
}));
|
|
4345
|
-
return _isUserSessionAdmin.apply(this, arguments);
|
|
4346
|
-
}
|
|
4347
|
-
|
|
4348
4928
|
function getRoleFromSupabaseUser$2(user) {
|
|
4349
4929
|
var _user$app_metadata, _user$user_metadata;
|
|
4350
4930
|
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;
|
|
@@ -4960,6 +5540,81 @@ function requireAuth(handler) {
|
|
|
4960
5540
|
}();
|
|
4961
5541
|
}
|
|
4962
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
|
+
|
|
4963
5618
|
function getRoleFromSupabaseUser$1(user) {
|
|
4964
5619
|
var _user$app_metadata, _user$user_metadata;
|
|
4965
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;
|
|
@@ -5440,6 +6095,10 @@ function createAuthRoute(app, tableName) {
|
|
|
5440
6095
|
});
|
|
5441
6096
|
return app;
|
|
5442
6097
|
}
|
|
6098
|
+
function createOssUploadRoute(app) {
|
|
6099
|
+
app.post("/upload", requireJwtAuth, requireAdminRole, uploadToOss);
|
|
6100
|
+
return app;
|
|
6101
|
+
}
|
|
5443
6102
|
// 一键创建所有CMS路由
|
|
5444
6103
|
function createCmsRoutes(app) {
|
|
5445
6104
|
createModelRoute(app);
|
|
@@ -5452,6 +6111,8 @@ exports.AuthService = AuthService;
|
|
|
5452
6111
|
exports.CmsModel = getCmsModelService;
|
|
5453
6112
|
exports.CmsModelService = CmsModelService;
|
|
5454
6113
|
exports.DynamicTableService = DynamicTableService;
|
|
6114
|
+
exports.OssUploadError = OssUploadError;
|
|
6115
|
+
exports.OssUploadService = OssUploadService;
|
|
5455
6116
|
exports.closeDatabase = closeSupabase;
|
|
5456
6117
|
exports.closeSupabase = closeSupabase;
|
|
5457
6118
|
exports.createAuthRoute = createAuthRoute;
|
|
@@ -5461,6 +6122,7 @@ exports.createDynamicAuthRoute = createDynamicAuthRoute;
|
|
|
5461
6122
|
exports.createDynamicDataRoute = createDynamicDataRoute;
|
|
5462
6123
|
exports.createModel = createModel;
|
|
5463
6124
|
exports.createModelRoute = createModelRoute;
|
|
6125
|
+
exports.createOssUploadRoute = createOssUploadRoute;
|
|
5464
6126
|
exports.createTableData = createTableData;
|
|
5465
6127
|
exports.deleteModel = deleteModel;
|
|
5466
6128
|
exports.deleteTableData = deleteTableData;
|
|
@@ -5472,6 +6134,7 @@ exports.getCurrentUser = getCurrentUser;
|
|
|
5472
6134
|
exports.getDatabase = getSupabase;
|
|
5473
6135
|
exports.getDynamicTableService = getDynamicTableService;
|
|
5474
6136
|
exports.getModels = getModels;
|
|
6137
|
+
exports.getOssUploadService = getOssUploadService;
|
|
5475
6138
|
exports.getRelationOptions = getRelationOptions;
|
|
5476
6139
|
exports.getSupabase = getSupabase;
|
|
5477
6140
|
exports.getSupabaseSetupSQL = getSupabaseSetupSQL;
|
|
@@ -5480,6 +6143,7 @@ exports.getTableDataWithRelations = getTableDataWithRelations;
|
|
|
5480
6143
|
exports.initializeCmsModel = initializeCmsModel;
|
|
5481
6144
|
exports.initializeCmsSystem = initializeCmsSystem;
|
|
5482
6145
|
exports.initializeDatabase = initializeSupabase;
|
|
6146
|
+
exports.initializeOssUpload = initializeOssUpload;
|
|
5483
6147
|
exports.initializeSupabase = initializeSupabase;
|
|
5484
6148
|
exports.login = login;
|
|
5485
6149
|
exports.requireAuth = requireAuth;
|
|
@@ -5489,5 +6153,6 @@ exports.syncDatabase = initializeCmsSystem;
|
|
|
5489
6153
|
exports.testConnection = testConnection;
|
|
5490
6154
|
exports.updateModel = updateModel;
|
|
5491
6155
|
exports.updateTableData = updateTableData;
|
|
6156
|
+
exports.uploadToOss = uploadToOss;
|
|
5492
6157
|
exports.verifyAuth = verifyAuth;
|
|
5493
6158
|
//# sourceMappingURL=index.js.map
|