@interware/content-generator 0.4.4 → 0.6.0
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 +21 -1
- package/dist/_chunks/{App-CfwvfmvL.js → App-CJxSC8yt.js} +32 -720
- package/dist/_chunks/{App-BQr5_g5u.mjs → App-qbgUXlOZ.mjs} +38 -726
- package/dist/_chunks/ImageStudioTabs-BLAH3KYv.mjs +5270 -0
- package/dist/_chunks/ImageStudioTabs-DtusqpQO.js +5271 -0
- package/dist/_chunks/PluginProviders-D79TeGSE.js +34 -0
- package/dist/_chunks/PluginProviders-DWMpcAIh.mjs +35 -0
- package/dist/_chunks/Settings-BQXxV3LO.js +242 -0
- package/dist/_chunks/Settings-o2GngLaW.mjs +242 -0
- package/dist/_chunks/StudioApp-BaySMwrk.js +18 -0
- package/dist/_chunks/StudioApp-C_znlQRo.mjs +18 -0
- package/dist/_chunks/{getTranslation-B9ND5RaH.mjs → getTranslation-B6Bsu-uq.mjs} +1 -1
- package/dist/_chunks/{getTranslation-DNhP1INv.js → getTranslation-BRVMWSf8.js} +1 -1
- package/dist/_chunks/{index-DGPqyrzz.js → index-BKhe-Jyx.js} +24 -6
- package/dist/_chunks/{index-Dyq8dxMX.mjs → index-BKigRXm3.mjs} +25 -7
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/components/PluginIcon.d.ts +4 -2
- package/dist/admin/src/components/PluginProviders.d.ts +12 -0
- package/dist/admin/src/components/generate-video/Form.d.ts +1 -1
- package/dist/admin/src/components/settings/Form.d.ts +4 -5
- package/dist/admin/src/components/settings/VertexSettings.d.ts +18 -0
- package/dist/admin/src/containers/settings/index.d.ts +7 -7
- package/dist/admin/src/features/background-removal/RemoveBackgroundButton.d.ts +7 -0
- package/dist/admin/src/features/background-removal/RemoveBackgroundDialog.d.ts +15 -0
- package/dist/admin/src/features/background-removal/colorKey.d.ts +29 -0
- package/dist/admin/src/features/background-removal/imageCanvas.d.ts +20 -0
- package/dist/admin/src/features/background-removal/mask.d.ts +10 -0
- package/dist/admin/src/features/background-removal/runtime.d.ts +31 -0
- package/dist/admin/src/features/generator/EditEmpty.d.ts +13 -0
- package/dist/admin/src/features/generator/GeneratorTab.d.ts +7 -0
- package/dist/admin/src/features/generator/GroundingSources.d.ts +9 -0
- package/dist/admin/src/features/generator/ModeSwitch.d.ts +6 -0
- package/dist/admin/src/features/generator/PromptComposer.d.ts +25 -0
- package/dist/admin/src/features/generator/ReferencePicker.d.ts +26 -0
- package/dist/admin/src/features/generator/VersionHistory.d.ts +13 -0
- package/dist/admin/src/features/generator/generatorApi.d.ts +71 -0
- package/dist/admin/src/features/generator/model.d.ts +60 -0
- package/dist/admin/src/features/generator/useGeneratorApi.d.ts +21 -0
- package/dist/admin/src/features/image-studio/ImageStudioTabs.d.ts +26 -0
- package/dist/admin/src/features/image-studio/SegmentedSwitch.d.ts +18 -0
- package/dist/admin/src/features/image-studio/checkerboard.d.ts +5 -0
- package/dist/admin/src/features/library/FileCard.d.ts +17 -0
- package/dist/admin/src/features/library/FolderTree.d.ts +14 -0
- package/dist/admin/src/features/library/LibraryDialogs.d.ts +46 -0
- package/dist/admin/src/features/library/LibraryImagePicker.d.ts +15 -0
- package/dist/admin/src/features/library/LibraryTab.d.ts +2 -0
- package/dist/admin/src/features/library/SaveToLibraryDialog.d.ts +15 -0
- package/dist/admin/src/features/library/model.d.ts +40 -0
- package/dist/admin/src/features/library/studioRoot.d.ts +11 -0
- package/dist/admin/src/features/library/uploadApi.d.ts +77 -0
- package/dist/admin/src/features/library/useLibraryApi.d.ts +34 -0
- package/dist/admin/src/features/templates/editor/ColorField.d.ts +11 -0
- package/dist/admin/src/features/templates/editor/Editor.d.ts +19 -0
- package/dist/admin/src/features/templates/editor/EditorBar.d.ts +9 -0
- package/dist/admin/src/features/templates/editor/EditorMenuBar.d.ts +58 -0
- package/dist/admin/src/features/templates/editor/EditorToolbar.d.ts +20 -0
- package/dist/admin/src/features/templates/editor/ElementPalette.d.ts +10 -0
- package/dist/admin/src/features/templates/editor/FloatingPanel.d.ts +17 -0
- package/dist/admin/src/features/templates/editor/FullscreenView.d.ts +11 -0
- package/dist/admin/src/features/templates/editor/IconPicker.d.ts +9 -0
- package/dist/admin/src/features/templates/editor/Inspector.d.ts +17 -0
- package/dist/admin/src/features/templates/editor/LayersPanel.d.ts +12 -0
- package/dist/admin/src/features/templates/editor/Precision.d.ts +23 -0
- package/dist/admin/src/features/templates/editor/RangeField.d.ts +12 -0
- package/dist/admin/src/features/templates/editor/SaveTemplateDialog.d.ts +14 -0
- package/dist/admin/src/features/templates/editor/Stage.d.ts +29 -0
- package/dist/admin/src/features/templates/editor/TemplateFolderSelect.d.ts +9 -0
- package/dist/admin/src/features/templates/editor/TemplatePicker.d.ts +23 -0
- package/dist/admin/src/features/templates/editor/TemplatesTab.d.ts +5 -0
- package/dist/admin/src/features/templates/editor/TypographyControls.d.ts +24 -0
- package/dist/admin/src/features/templates/editor/icons.d.ts +7 -0
- package/dist/admin/src/features/templates/editor/overlays.d.ts +20 -0
- package/dist/admin/src/features/templates/editor/useCanvasNav.d.ts +25 -0
- package/dist/admin/src/features/templates/editor/useFitScale.d.ts +3 -0
- package/dist/admin/src/features/templates/export/fontEmbed.d.ts +22 -0
- package/dist/admin/src/features/templates/export/imageSource.d.ts +21 -0
- package/dist/admin/src/features/templates/export/pdf.d.ts +6 -0
- package/dist/admin/src/features/templates/export/render.d.ts +22 -0
- package/dist/admin/src/features/templates/export/useEditorIO.d.ts +18 -0
- package/dist/admin/src/features/templates/fonts/catalog.d.ts +47 -0
- package/dist/admin/src/features/templates/fonts/customFonts.d.ts +19 -0
- package/dist/admin/src/features/templates/fonts/useCustomFonts.d.ts +9 -0
- package/dist/admin/src/features/templates/fonts/useFonts.d.ts +2 -0
- package/dist/admin/src/features/templates/model/drag.d.ts +10 -0
- package/dist/admin/src/features/templates/model/editorReducer.d.ts +58 -0
- package/dist/admin/src/features/templates/model/layers.d.ts +42 -0
- package/dist/admin/src/features/templates/model/palette.d.ts +38 -0
- package/dist/admin/src/features/templates/model/presets.d.ts +17 -0
- package/dist/admin/src/features/templates/model/shortcuts.d.ts +19 -0
- package/dist/admin/src/features/templates/model/snap.d.ts +24 -0
- package/dist/admin/src/features/templates/model/templates.d.ts +8 -0
- package/dist/admin/src/features/templates/model/types.d.ts +154 -0
- package/dist/admin/src/features/templates/model/viewport.d.ts +36 -0
- package/dist/admin/src/features/templates/render/IWLogo.d.ts +7 -0
- package/dist/admin/src/features/templates/render/LayerCanvas.d.ts +13 -0
- package/dist/admin/src/features/templates/render/fonts.d.ts +5 -0
- package/dist/admin/src/features/templates/render/icons.d.ts +10 -0
- package/dist/admin/src/features/templates/render/renderLayer.d.ts +9 -0
- package/dist/admin/src/features/templates/store/persist.d.ts +41 -0
- package/dist/admin/src/features/templates/store/templatesApi.d.ts +49 -0
- package/dist/admin/src/features/templates/store/useMyTemplates.d.ts +19 -0
- package/dist/admin/src/features/templates/store/useTemplateSaving.d.ts +14 -0
- package/dist/admin/src/features/templates/store/useTemplatesApi.d.ts +23 -0
- package/dist/admin/src/hooks/useAdminTheme.d.ts +8 -0
- package/dist/admin/src/hooks/useThemeColors.d.ts +9 -0
- package/dist/admin/src/lib/dataUrl.d.ts +6 -0
- package/dist/admin/src/lib/promptRules.d.ts +23 -0
- package/dist/admin/src/lib/use-cases/articles/index.d.ts +12 -1
- package/dist/admin/src/lib/use-cases/categories/index.d.ts +12 -1
- package/dist/admin/src/lib/use-cases/facebook/index.d.ts +1 -1
- package/dist/admin/src/lib/use-cases/generate-content/index.d.ts +2 -2
- package/dist/admin/src/lib/use-cases/images/index.d.ts +1 -4
- package/dist/admin/src/lib/use-cases/linkedin/index.d.ts +1 -1
- package/dist/admin/src/lib/use-cases/settings/index.d.ts +14 -2
- package/dist/admin/src/lib/use-cases/users/index.d.ts +12 -1
- package/dist/admin/src/pages/ImageStudio.d.ts +3 -0
- package/dist/admin/src/pages/StudioApp.d.ts +3 -0
- package/dist/admin/src/pluginId.d.ts +6 -0
- package/dist/admin/src/test-setup.d.ts +1 -0
- package/dist/admin/src/test-utils.d.ts +5 -0
- package/dist/server/index.js +2494 -1279
- package/dist/server/index.mjs +2501 -1285
- package/dist/server/src/bootstrap.d.ts +1 -1
- package/dist/server/src/content-types/index.d.ts +66 -1
- package/dist/server/src/content-types/template/index.d.ts +65 -0
- package/dist/server/src/content-types/template/schema.d.ts +69 -0
- package/dist/server/src/controllers/config.d.ts +10 -0
- package/dist/server/src/controllers/controller.d.ts +0 -5
- package/dist/server/src/controllers/image-studio.d.ts +23 -0
- package/dist/server/src/controllers/index.d.ts +129 -5
- package/dist/server/src/controllers/templates.d.ts +26 -0
- package/dist/server/src/image-studio/geminiConfig.d.ts +40 -0
- package/dist/server/src/image-studio/models.d.ts +39 -0
- package/dist/server/src/image-studio/prompt.d.ts +7 -0
- package/dist/server/src/image-studio/validate.d.ts +41 -0
- package/dist/server/src/index.d.ts +233 -75
- package/dist/server/src/routes/admin.d.ts +6 -2
- package/dist/server/src/routes/content-api.d.ts +4 -9
- package/dist/server/src/routes/index.d.ts +7 -11
- package/dist/server/src/routes/policies.d.ts +14 -0
- package/dist/server/src/services/image-studio.d.ts +66 -0
- package/dist/server/src/services/index.d.ts +30 -57
- package/dist/server/src/services/service.d.ts +10 -57
- package/dist/server/src/services/templates.d.ts +81 -0
- package/dist/server/src/templates/folders.d.ts +14 -0
- package/dist/server/src/templates/validate.d.ts +23 -0
- package/dist/server/src/utils/folders.d.ts +15 -0
- package/dist/server/src/utils/geminiClient.d.ts +24 -0
- package/dist/server/src/utils/secrets.d.ts +9 -0
- package/dist/server/src/utils/serviceAccount.d.ts +29 -0
- package/package.json +23 -10
- package/static/background-worker.d.mts +15 -0
- package/static/background-worker.mjs +87 -0
- package/dist/_chunks/Settings-BrqTzJp-.js +0 -262
- package/dist/_chunks/Settings-CdZnYLLK.mjs +0 -244
- package/dist/admin/src/components/Navigation.d.ts +0 -2
- package/dist/admin/src/components/generate-image/Form.d.ts +0 -15
- package/dist/admin/src/components/generate-images/Image.d.ts +0 -5
- package/dist/admin/src/components/generate-images/Images.d.ts +0 -2
- package/dist/admin/src/components/generate-images/Modal.d.ts +0 -9
- package/dist/admin/src/containers/generate-image/index.d.ts +0 -2
- package/dist/admin/src/containers/generate-images/index.d.ts +0 -2
- package/dist/admin/src/hooks/generate-images/useImages.d.ts +0 -12
- package/dist/admin/src/pages/GenerateImage.d.ts +0 -2
- package/dist/admin/src/pages/GenerateImages.d.ts +0 -2
package/dist/server/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const genai = require("@google/genai");
|
|
3
2
|
const fs = require("fs");
|
|
3
|
+
const genai = require("@google/genai");
|
|
4
4
|
function _interopNamespace(e) {
|
|
5
5
|
if (e && e.__esModule) return e;
|
|
6
6
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -20,7 +20,28 @@ function _interopNamespace(e) {
|
|
|
20
20
|
}
|
|
21
21
|
const fs__namespace = /* @__PURE__ */ _interopNamespace(fs);
|
|
22
22
|
const PLUGIN_ID = "strapi-content-generator-gemini";
|
|
23
|
-
const
|
|
23
|
+
const FOLDER_UID = "plugin::upload.folder";
|
|
24
|
+
const hasValidPath = (path) => /^(\/\d+)+$/.test(path);
|
|
25
|
+
const repairFolderPaths = async (strapi, name2) => {
|
|
26
|
+
const query = strapi.db.query(FOLDER_UID);
|
|
27
|
+
const folders = await query.findMany({ where: { name: name2 }, populate: ["parent"] });
|
|
28
|
+
const repaired = [];
|
|
29
|
+
for (const f of folders) {
|
|
30
|
+
if (hasValidPath(f.path)) continue;
|
|
31
|
+
const to = `${f.parent?.path ?? ""}/${f.pathId}`;
|
|
32
|
+
await query.update({ where: { id: f.id }, data: { path: to } });
|
|
33
|
+
repaired.push({ id: f.id, from: f.path, to });
|
|
34
|
+
}
|
|
35
|
+
return repaired;
|
|
36
|
+
};
|
|
37
|
+
const ensureFolder = async (strapi, name2) => {
|
|
38
|
+
const folders = await strapi.db.query(FOLDER_UID).findMany({ where: { name: name2 }, populate: ["parent"] });
|
|
39
|
+
const atRoot = folders.find((f) => !f.parent);
|
|
40
|
+
if (atRoot) return atRoot.id;
|
|
41
|
+
const created = await strapi.plugin("upload").service("folder").create({ name: name2, parent: null });
|
|
42
|
+
return created.id;
|
|
43
|
+
};
|
|
44
|
+
const bootstrap = async ({ strapi }) => {
|
|
24
45
|
strapi.admin.services.permission.actionProvider.registerMany([
|
|
25
46
|
{
|
|
26
47
|
section: "plugins",
|
|
@@ -29,17 +50,56 @@ const bootstrap = ({ strapi }) => {
|
|
|
29
50
|
pluginName: PLUGIN_ID
|
|
30
51
|
}
|
|
31
52
|
]);
|
|
53
|
+
try {
|
|
54
|
+
for (const r of await repairFolderPaths(strapi, "Generated")) {
|
|
55
|
+
strapi.log.info(`[content-generator] path de carpeta ${r.id} corregido: ${r.from} → ${r.to}`);
|
|
56
|
+
}
|
|
57
|
+
} catch (err) {
|
|
58
|
+
strapi.log.warn(`[content-generator] no se pudo revisar el path de «Generated»: ${err.message}`);
|
|
59
|
+
}
|
|
32
60
|
};
|
|
33
61
|
const destroy = ({ strapi }) => {
|
|
34
62
|
};
|
|
35
63
|
const register = ({ strapi }) => {
|
|
36
64
|
};
|
|
37
|
-
const config$
|
|
65
|
+
const config$2 = {
|
|
38
66
|
default: {},
|
|
39
67
|
validator() {
|
|
40
68
|
}
|
|
41
69
|
};
|
|
42
|
-
const
|
|
70
|
+
const schema = {
|
|
71
|
+
kind: "collectionType",
|
|
72
|
+
collectionName: "iw_image_templates",
|
|
73
|
+
info: {
|
|
74
|
+
singularName: "template",
|
|
75
|
+
pluralName: "templates",
|
|
76
|
+
displayName: "Template de imagen",
|
|
77
|
+
description: "Templates del Estudio de imágenes (content-generator)"
|
|
78
|
+
},
|
|
79
|
+
options: { draftAndPublish: false },
|
|
80
|
+
pluginOptions: {
|
|
81
|
+
"content-manager": { visible: false },
|
|
82
|
+
"content-type-builder": { visible: false }
|
|
83
|
+
},
|
|
84
|
+
attributes: {
|
|
85
|
+
name: { type: "string", required: true, maxLength: 120 },
|
|
86
|
+
folder: { type: "string", default: "" },
|
|
87
|
+
width: { type: "integer", required: true },
|
|
88
|
+
height: { type: "integer", required: true },
|
|
89
|
+
background: { type: "string", default: "#FFFFFF" },
|
|
90
|
+
safeMargin: { type: "integer", default: 0 },
|
|
91
|
+
gridUnit: { type: "integer", default: 60 },
|
|
92
|
+
layers: { type: "json", required: true },
|
|
93
|
+
/** Base de la que se copió (origen). */
|
|
94
|
+
baseId: { type: "string" },
|
|
95
|
+
/** Si está, esta fila es la versión editada de esa plantilla base (S4.15): una por base. */
|
|
96
|
+
replacesBase: { type: "string" }
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const template = { schema };
|
|
100
|
+
const contentTypes = {
|
|
101
|
+
template
|
|
102
|
+
};
|
|
43
103
|
const controller = ({ strapi }) => {
|
|
44
104
|
const pluginService = () => strapi.plugin("strapi-content-generator-gemini").service("service");
|
|
45
105
|
return {
|
|
@@ -94,39 +154,12 @@ const controller = ({ strapi }) => {
|
|
|
94
154
|
auth: ctx.state.auth
|
|
95
155
|
});
|
|
96
156
|
},
|
|
97
|
-
async getImages(ctx) {
|
|
98
|
-
const contentType = strapi.contentType("plugin::upload.file");
|
|
99
|
-
const files = await pluginService().getImagenes();
|
|
100
|
-
return await strapi.contentAPI.sanitize.output(files, contentType, {
|
|
101
|
-
auth: ctx.state.auth
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
async deleteImage(ctx) {
|
|
105
|
-
const contentType = strapi.contentType("plugin::upload.file");
|
|
106
|
-
await strapi.contentAPI.validate.query(ctx.query, contentType, {
|
|
107
|
-
auth: ctx.state.auth
|
|
108
|
-
});
|
|
109
|
-
const sanitizedQueryParams = await strapi.contentAPI.sanitize.query(
|
|
110
|
-
ctx.query,
|
|
111
|
-
contentType,
|
|
112
|
-
{
|
|
113
|
-
auth: ctx.state.auth
|
|
114
|
-
}
|
|
115
|
-
);
|
|
116
|
-
const file = await pluginService().eliminarImagen(sanitizedQueryParams);
|
|
117
|
-
return await strapi.contentAPI.sanitize.output(file, contentType, {
|
|
118
|
-
auth: ctx.state.auth
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
157
|
async generateArticle(ctx) {
|
|
122
158
|
ctx.body = await pluginService().generateArticle(ctx);
|
|
123
159
|
},
|
|
124
160
|
async generateImageForArticle(ctx) {
|
|
125
161
|
ctx.body = await pluginService().generateImageForArticle(ctx);
|
|
126
162
|
},
|
|
127
|
-
async generateImage(ctx) {
|
|
128
|
-
ctx.body = await pluginService().generateImage(ctx);
|
|
129
|
-
},
|
|
130
163
|
async downloadFile(ctx) {
|
|
131
164
|
await pluginService().downloadFile(ctx);
|
|
132
165
|
},
|
|
@@ -138,195 +171,769 @@ const controller = ({ strapi }) => {
|
|
|
138
171
|
},
|
|
139
172
|
async publishToFacebook(ctx) {
|
|
140
173
|
ctx.body = await pluginService().publishToFacebook(ctx);
|
|
141
|
-
},
|
|
142
|
-
async get(ctx) {
|
|
143
|
-
const pluginStore = strapi.store({
|
|
144
|
-
type: "plugin",
|
|
145
|
-
name: "strapi-content-generator-gemini"
|
|
146
|
-
});
|
|
147
|
-
const googleGenAI = await pluginStore.get({ key: "GOOGLE_GEN_AI" });
|
|
148
|
-
const clientURL = await pluginStore.get({ key: "CLIENT_URL" });
|
|
149
|
-
const previewSecret = await pluginStore.get({ key: "PREVIEW_SECRET" });
|
|
150
|
-
ctx.body = { googleGenAI, clientURL, previewSecret };
|
|
151
|
-
},
|
|
152
|
-
async set(ctx) {
|
|
153
|
-
const { key1, key2, key3 } = ctx.request.body;
|
|
154
|
-
const pluginStore = strapi.store({
|
|
155
|
-
type: "plugin",
|
|
156
|
-
name: "strapi-content-generator-gemini"
|
|
157
|
-
});
|
|
158
|
-
await pluginStore.set({ key: "GOOGLE_GEN_AI", value: key1 });
|
|
159
|
-
await pluginStore.set({ key: "CLIENT_URL", value: key2 });
|
|
160
|
-
await pluginStore.set({ key: "PREVIEW_SECRET", value: key3 });
|
|
161
|
-
ctx.body = { ok: true };
|
|
162
174
|
}
|
|
163
175
|
};
|
|
164
176
|
};
|
|
165
|
-
const
|
|
177
|
+
const maskSecret = (value) => {
|
|
178
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
179
|
+
return { configured: false, last4: null };
|
|
180
|
+
}
|
|
181
|
+
return { configured: true, last4: value.slice(-4) };
|
|
182
|
+
};
|
|
183
|
+
const VERTEX_KEY = "VERTEX_SERVICE_ACCOUNT";
|
|
184
|
+
const REQUIRED = ["project_id", "client_email", "private_key"];
|
|
185
|
+
const parseServiceAccount = (value) => {
|
|
186
|
+
if (typeof value !== "string") return { ok: false, message: "El texto no es un JSON válido." };
|
|
187
|
+
let data;
|
|
188
|
+
try {
|
|
189
|
+
const parsed = JSON.parse(value);
|
|
190
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error();
|
|
191
|
+
data = parsed;
|
|
192
|
+
} catch {
|
|
193
|
+
return { ok: false, message: "El texto no es un JSON válido." };
|
|
194
|
+
}
|
|
195
|
+
if (data.type !== "service_account") {
|
|
196
|
+
return { ok: false, message: "El JSON no es de una cuenta de servicio (type debe ser service_account)." };
|
|
197
|
+
}
|
|
198
|
+
const missing = REQUIRED.filter((k) => typeof data[k] !== "string" || data[k].trim() === "");
|
|
199
|
+
if (missing.length) return { ok: false, message: `El JSON no es de una cuenta de servicio: falta ${missing.join(", ")}.` };
|
|
200
|
+
return {
|
|
201
|
+
ok: true,
|
|
202
|
+
account: { projectId: data.project_id, clientEmail: data.client_email, privateKey: data.private_key }
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
const storedServiceAccount = (account) => JSON.stringify({ type: "service_account", project_id: account.projectId, client_email: account.clientEmail, private_key: account.privateKey });
|
|
206
|
+
const publicServiceAccount = (stored) => {
|
|
207
|
+
const parsed = parseServiceAccount(stored);
|
|
208
|
+
if (!("account" in parsed)) return { configured: false, projectId: null, clientEmail: null };
|
|
209
|
+
return { configured: true, projectId: parsed.account.projectId, clientEmail: parsed.account.clientEmail };
|
|
210
|
+
};
|
|
211
|
+
const CREDENTIALS = {
|
|
212
|
+
googleGenAI: "GOOGLE_GEN_AI",
|
|
213
|
+
linkedInAccessToken: "LINKEDIN_ACCESS_TOKEN",
|
|
214
|
+
linkedInOrganizationId: "LINKEDIN_ORGANIZATION_ID",
|
|
215
|
+
facebookClientToken: "FACEBOOK_CLIENT_TOKEN",
|
|
216
|
+
facebookPageId: "FACEBOOK_PAGE_ID"
|
|
217
|
+
};
|
|
218
|
+
const FIELDS$1 = Object.keys(CREDENTIALS);
|
|
219
|
+
const config$1 = ({ strapi }) => {
|
|
220
|
+
const pluginStore = () => strapi.store({
|
|
221
|
+
type: "plugin",
|
|
222
|
+
name: "strapi-content-generator-gemini"
|
|
223
|
+
});
|
|
166
224
|
return {
|
|
225
|
+
/**
|
|
226
|
+
* Devuelve si cada credencial está guardada y sus últimos 4 caracteres, nunca el valor. Para Vertex,
|
|
227
|
+
* el proyecto y el correo de la cuenta de servicio, nunca la llave privada.
|
|
228
|
+
*/
|
|
167
229
|
async get(ctx) {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const linkedInAccessToken = await pluginStore.get({ key: "LINKEDIN_ACCESS_TOKEN" });
|
|
174
|
-
const linkedInOrganizationId = await pluginStore.get({ key: "LINKEDIN_ORGANIZATION_ID" });
|
|
175
|
-
const facebookClientToken = await pluginStore.get({ key: "FACEBOOK_CLIENT_TOKEN" });
|
|
176
|
-
const facebookPageId = await pluginStore.get({ key: "FACEBOOK_PAGE_ID" });
|
|
177
|
-
ctx.body = { googleGenAI, linkedInAccessToken, linkedInOrganizationId, facebookClientToken, facebookPageId };
|
|
230
|
+
const store = pluginStore();
|
|
231
|
+
const entries = await Promise.all(
|
|
232
|
+
FIELDS$1.map(async (field) => [field, maskSecret(await store.get({ key: CREDENTIALS[field] }))])
|
|
233
|
+
);
|
|
234
|
+
ctx.body = { ...Object.fromEntries(entries), vertex: publicServiceAccount(await store.get({ key: VERTEX_KEY })) };
|
|
178
235
|
},
|
|
236
|
+
/**
|
|
237
|
+
* Escribe solo las credenciales conocidas que llegan como texto no vacío. Una cuenta de servicio
|
|
238
|
+
* inválida rechaza la petición completa (400) antes de escribir nada.
|
|
239
|
+
*/
|
|
179
240
|
async set(ctx) {
|
|
180
|
-
const
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
await
|
|
189
|
-
|
|
241
|
+
const body = ctx.request.body ?? {};
|
|
242
|
+
const store = pluginStore();
|
|
243
|
+
const vertex = typeof body.vertexServiceAccount === "string" && body.vertexServiceAccount.trim() !== "" ? parseServiceAccount(body.vertexServiceAccount) : null;
|
|
244
|
+
if (vertex && "message" in vertex) {
|
|
245
|
+
ctx.status = 400;
|
|
246
|
+
ctx.body = { data: null, error: { status: 400, name: "ValidationError", message: vertex.message } };
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (vertex && "account" in vertex) await store.set({ key: VERTEX_KEY, value: storedServiceAccount(vertex.account) });
|
|
250
|
+
for (const field of FIELDS$1) {
|
|
251
|
+
const value = body[field];
|
|
252
|
+
if (typeof value === "string" && value.length > 0) {
|
|
253
|
+
await store.set({ key: CREDENTIALS[field], value });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
ctx.body = { ok: true };
|
|
257
|
+
},
|
|
258
|
+
/** Quita la cuenta de servicio: el plugin vuelve a la llave de la Gemini API (S5.1). */
|
|
259
|
+
async removeVertex(ctx) {
|
|
260
|
+
await pluginStore().delete({ key: VERTEX_KEY });
|
|
190
261
|
ctx.body = { ok: true };
|
|
191
262
|
}
|
|
192
263
|
};
|
|
193
264
|
};
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
265
|
+
const PEOPLE_CLAUSE = "STRICTLY NO people, NO humans, NO faces, NO hands.";
|
|
266
|
+
const HARM_CATEGORIES = [
|
|
267
|
+
genai.HarmCategory.HARM_CATEGORY_HARASSMENT,
|
|
268
|
+
genai.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
|
|
269
|
+
genai.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
|
|
270
|
+
genai.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT
|
|
271
|
+
];
|
|
272
|
+
const safetySettings = (safety) => HARM_CATEGORIES.map((category) => ({
|
|
273
|
+
category,
|
|
274
|
+
threshold: safety ? genai.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE : genai.HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
275
|
+
}));
|
|
276
|
+
const PEOPLE = {
|
|
277
|
+
none: "ALLOW_NONE",
|
|
278
|
+
adults: genai.PersonGeneration.ALLOW_ADULT
|
|
197
279
|
};
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
{
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
{
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
280
|
+
const imageConfig = ({ aspectRatio, imageSize, allowPeople }, backend = "gemini-api") => ({
|
|
281
|
+
...aspectRatio ? { aspectRatio } : {},
|
|
282
|
+
...imageSize ? { imageSize } : {},
|
|
283
|
+
...backend === "vertex" ? { personGeneration: allowPeople ? PEOPLE.adults : PEOPLE.none } : {}
|
|
284
|
+
});
|
|
285
|
+
const promptPart = (text2, allowPeople, backend = "gemini-api") => ({
|
|
286
|
+
text: backend === "gemini-api" && !allowPeople ? `${text2} ${PEOPLE_CLAUSE}` : text2
|
|
287
|
+
});
|
|
288
|
+
const searchTool = () => ({ googleSearch: { searchTypes: { webSearch: {}, imageSearch: {} } } });
|
|
289
|
+
const generateConfig = ({ aspectRatio, imageSize, allowPeople, safety, grounding }, backend = "gemini-api") => ({
|
|
290
|
+
// Con búsqueda el modelo responde texto e imagen.
|
|
291
|
+
responseModalities: grounding ? [genai.Modality.TEXT, genai.Modality.IMAGE] : [genai.Modality.IMAGE],
|
|
292
|
+
imageConfig: imageConfig({ aspectRatio, imageSize, allowPeople }, backend),
|
|
293
|
+
safetySettings: safetySettings(safety),
|
|
294
|
+
...grounding ? { tools: [searchTool()] } : {}
|
|
295
|
+
});
|
|
296
|
+
const editConfig = ({ safety, allowPeople, aspectRatio }, backend = "gemini-api") => ({
|
|
297
|
+
responseModalities: [genai.Modality.IMAGE],
|
|
298
|
+
imageConfig: imageConfig({ aspectRatio, allowPeople }, backend),
|
|
299
|
+
safetySettings: safetySettings(safety)
|
|
300
|
+
});
|
|
301
|
+
const inlinePart = (bytes, mimeType) => ({ inlineData: { mimeType, data: bytes.toString("base64") } });
|
|
302
|
+
const RATIOS = ["1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"];
|
|
303
|
+
const FLASH_RATIOS = [...RATIOS, "1:4", "4:1", "1:8", "8:1"];
|
|
304
|
+
const FLASH = { maxReferences: 6, sizes: ["512", "1K", "2K", "4K"], aspectRatios: FLASH_RATIOS, canEdit: true, grounding: true };
|
|
305
|
+
const FLASH_LITE = { maxReferences: 6, sizes: ["512", "1K"], aspectRatios: RATIOS, canEdit: true, grounding: false };
|
|
306
|
+
const PRO = { maxReferences: 6, sizes: ["1K", "2K", "4K"], aspectRatios: RATIOS, canEdit: true, grounding: false };
|
|
307
|
+
const IMAGE_MODELS = [
|
|
308
|
+
{ id: "gemini-3.1-flash-image", label: "Nano Banana 2", ...FLASH },
|
|
309
|
+
{ id: "gemini-3.1-flash-image-preview", label: "Nano Banana 2 (preview)", ...FLASH },
|
|
310
|
+
{ id: "gemini-3.1-flash-lite-image", label: "Nano Banana 2 Lite", ...FLASH_LITE },
|
|
311
|
+
{ id: "gemini-3.1-flash-lite-image-preview", label: "Nano Banana 2 Lite (preview)", ...FLASH_LITE },
|
|
312
|
+
{ id: "gemini-3-pro-image", label: "Nano Banana Pro", ...PRO },
|
|
313
|
+
{ id: "gemini-3-pro-image-preview", label: "Nano Banana Pro (preview)", ...PRO },
|
|
314
|
+
{ id: "gemini-2.5-flash-image", label: "Nano Banana (legado)", maxReferences: 3, sizes: [], aspectRatios: RATIOS, canEdit: true, grounding: false }
|
|
315
|
+
];
|
|
316
|
+
const findModel = (id) => IMAGE_MODELS.find((m) => m.id === id);
|
|
317
|
+
const availableModels = (listed) => {
|
|
318
|
+
if (!listed) return { models: IMAGE_MODELS, verified: false };
|
|
319
|
+
const ids = new Set(listed.map((n) => n.replace(/^(publishers\/google\/)?models\//, "")));
|
|
320
|
+
const models = IMAGE_MODELS.filter((m) => ids.has(m.id) && !(m.id.endsWith("-preview") && ids.has(m.id.replace(/-preview$/, ""))));
|
|
321
|
+
return models.length ? { models, verified: true } : { models: IMAGE_MODELS, verified: false };
|
|
322
|
+
};
|
|
323
|
+
const editModelFor = (id) => {
|
|
324
|
+
const chosen = findModel(id);
|
|
325
|
+
if (chosen?.canEdit) return chosen;
|
|
326
|
+
return IMAGE_MODELS.find((m) => m.canEdit);
|
|
327
|
+
};
|
|
328
|
+
const PROMPT_MAX = 2e3;
|
|
329
|
+
const CONTROL = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g;
|
|
330
|
+
const INVISIBLE = /[----]/g;
|
|
331
|
+
const TAG = /<\/?[a-z][^>]*>/gi;
|
|
332
|
+
const sanitizePrompt = (text2) => text2.normalize("NFC").replace(CONTROL, "").replace(INVISIBLE, "").replace(TAG, "").replace(/\s+/g, " ").trim();
|
|
333
|
+
const PROMPT_LABELS = { label: "El prompt", empty: "Escribe un prompt." };
|
|
334
|
+
const INSTRUCTION_LABELS = { label: "La instrucción", empty: "Describe el cambio que quieres." };
|
|
335
|
+
const checkPrompt = (text2, { label, empty } = PROMPT_LABELS) => {
|
|
336
|
+
const clean2 = sanitizePrompt(text2);
|
|
337
|
+
if (!clean2) return { ok: false, error: empty };
|
|
338
|
+
if ([...clean2].length > PROMPT_MAX) return { ok: false, error: `${label} puede tener hasta ${PROMPT_MAX} caracteres.` };
|
|
339
|
+
return { ok: true, text: clean2 };
|
|
340
|
+
};
|
|
341
|
+
const cleanPrompt = sanitizePrompt;
|
|
342
|
+
const EXPAND_INSTRUCTION = (concept) => [
|
|
343
|
+
"Eres experto en prompts para generadores de imágenes con IA.",
|
|
344
|
+
"Expande y mejora este concepto con sujeto, composición, estilo, iluminación y color.",
|
|
345
|
+
"Responde solo con el prompt mejorado, en español, sin explicaciones, comillas ni viñetas.",
|
|
346
|
+
`Concepto: ${concept}`
|
|
347
|
+
].join("\n");
|
|
348
|
+
class BlockedError extends Error {
|
|
349
|
+
}
|
|
350
|
+
const sourceOf = (chunk) => {
|
|
351
|
+
if (chunk.web?.uri) return { title: chunk.web.title || new URL(chunk.web.uri).hostname, uri: chunk.web.uri };
|
|
352
|
+
const img = chunk.image;
|
|
353
|
+
if (img?.sourceUri) return { title: img.title || img.domain || new URL(img.sourceUri).hostname, uri: img.sourceUri };
|
|
354
|
+
return null;
|
|
355
|
+
};
|
|
356
|
+
const groundingFrom = (res) => {
|
|
357
|
+
const meta = res.candidates?.[0]?.groundingMetadata;
|
|
358
|
+
const sources = (meta?.groundingChunks ?? []).map(sourceOf).filter((src) => src !== null).filter((src, i, all3) => all3.findIndex((o) => o.title === src.title) === i);
|
|
359
|
+
const queries = [.../* @__PURE__ */ new Set([...meta?.webSearchQueries ?? [], ...meta?.imageSearchQueries ?? []])];
|
|
360
|
+
const suggestions = meta?.searchEntryPoint?.renderedContent;
|
|
361
|
+
if (!sources.length && !queries.length && !suggestions) return void 0;
|
|
362
|
+
return { ...suggestions ? { suggestions } : {}, queries, sources };
|
|
363
|
+
};
|
|
364
|
+
const EXPAND_MODEL = "gemini-2.5-flash";
|
|
365
|
+
const BLOCK_REASONS = {
|
|
366
|
+
SAFETY: "El modelo bloqueó la solicitud por seguridad. Ajusta el prompt o la imagen.",
|
|
367
|
+
PROHIBITED_CONTENT: "El modelo bloqueó la solicitud por contenido no permitido.",
|
|
368
|
+
IMAGE_SAFETY: "El modelo bloqueó la imagen resultante por seguridad."
|
|
369
|
+
};
|
|
370
|
+
const imageFrom = (res, model) => {
|
|
371
|
+
const parts = res.candidates?.[0]?.content?.parts ?? [];
|
|
372
|
+
const part = parts.find((p) => p.inlineData?.data && (p.inlineData.mimeType ?? "").startsWith("image/"));
|
|
373
|
+
if (part?.inlineData?.data) return { image: part.inlineData.data, mimeType: part.inlineData.mimeType ?? "image/png", model };
|
|
374
|
+
const reason = res.promptFeedback?.blockReason ?? res.candidates?.[0]?.finishReason;
|
|
375
|
+
throw new BlockedError(BLOCK_REASONS[String(reason)] ?? "El modelo no devolvió una imagen. Intenta con otro prompt.");
|
|
376
|
+
};
|
|
377
|
+
const inline = async (file, read) => inlinePart(await read(file.filepath), file.mimetype ?? "image/png");
|
|
378
|
+
const userTurn = (parts) => [{ role: "user", parts }];
|
|
379
|
+
const createImageStudio = (getClient, read = (p) => fs.promises.readFile(p)) => ({
|
|
380
|
+
async models() {
|
|
381
|
+
try {
|
|
382
|
+
const { models: api } = await getClient();
|
|
383
|
+
const names = [];
|
|
384
|
+
for await (const m of await api.list({ config: { pageSize: 100 } })) if (m.name) names.push(m.name);
|
|
385
|
+
return availableModels(names);
|
|
386
|
+
} catch {
|
|
387
|
+
return availableModels(null);
|
|
217
388
|
}
|
|
218
389
|
},
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
390
|
+
/**
|
|
391
|
+
* Imagen para un artículo (S4.12): antes usaba Imagen 4, que Google apagó. Usa el primer modelo
|
|
392
|
+
* disponible del catálogo y ajusta proporción y tamaño a lo que admite. Devuelve base64.
|
|
393
|
+
*/
|
|
394
|
+
async generateForArticle(prompt, aspectRatio, imageSize) {
|
|
395
|
+
const [model] = (await this.models()).models;
|
|
396
|
+
const { image } = await this.generate({
|
|
397
|
+
prompt,
|
|
398
|
+
model,
|
|
399
|
+
aspectRatio: model.aspectRatios.includes(aspectRatio) ? aspectRatio : "16:9",
|
|
400
|
+
imageSize: model.sizes.includes(imageSize) ? imageSize : void 0,
|
|
401
|
+
safety: true,
|
|
402
|
+
// El estilo de marca de los artículos no lleva personas (su JSON ya lo pide); ahora también el parámetro.
|
|
403
|
+
allowPeople: false,
|
|
404
|
+
grounding: false,
|
|
405
|
+
references: []
|
|
406
|
+
});
|
|
407
|
+
return image;
|
|
227
408
|
},
|
|
228
|
-
{
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
409
|
+
async generate(input) {
|
|
410
|
+
const { models: api, backend } = await getClient();
|
|
411
|
+
const text2 = cleanPrompt(input.prompt);
|
|
412
|
+
const { model } = input;
|
|
413
|
+
const refs = await Promise.all(input.references.map((f) => inline(f, read)));
|
|
414
|
+
const request = {
|
|
415
|
+
model: model.id,
|
|
416
|
+
contents: userTurn([promptPart(text2, input.allowPeople, backend), ...refs]),
|
|
417
|
+
config: generateConfig(input, backend)
|
|
418
|
+
};
|
|
419
|
+
const res = await api.generateContent(request);
|
|
420
|
+
const image = imageFrom(res, model.id);
|
|
421
|
+
const grounding = input.grounding ? groundingFrom(res) : void 0;
|
|
422
|
+
return grounding ? { ...image, grounding } : image;
|
|
236
423
|
},
|
|
237
|
-
{
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
424
|
+
async edit(input) {
|
|
425
|
+
const { models: api, backend } = await getClient();
|
|
426
|
+
const parts = [
|
|
427
|
+
await inline(input.image, read),
|
|
428
|
+
...await Promise.all(input.references.map((f) => inline(f, read))),
|
|
429
|
+
promptPart(input.instruction, input.allowPeople, backend)
|
|
430
|
+
];
|
|
431
|
+
const request = { model: input.model.id, contents: userTurn(parts), config: editConfig(input, backend) };
|
|
432
|
+
const res = await api.generateContent(request);
|
|
433
|
+
return imageFrom(res, input.model.id);
|
|
245
434
|
},
|
|
246
|
-
{
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
435
|
+
async expand(prompt) {
|
|
436
|
+
const { models: api } = await getClient();
|
|
437
|
+
const res = await api.generateContent({ model: EXPAND_MODEL, contents: EXPAND_INSTRUCTION(cleanPrompt(prompt)) });
|
|
438
|
+
const text2 = (res.text ?? "").trim().replace(/^["'«“]+|["'»”]+$/g, "").trim();
|
|
439
|
+
if (!text2) throw new BlockedError("No se pudo expandir la idea. Intenta de nuevo.");
|
|
440
|
+
return text2;
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
const imageStudio$1 = ({ strapi }) => createImageStudio(async () => {
|
|
444
|
+
const { ai, backend } = await strapi.plugin("strapi-content-generator-gemini").service("service").geminiClient();
|
|
445
|
+
return { models: ai.models, backend };
|
|
446
|
+
});
|
|
447
|
+
class InputError extends Error {
|
|
448
|
+
}
|
|
449
|
+
const ALLOWED = ["image/png", "image/jpeg", "image/webp"];
|
|
450
|
+
const MAX_BYTES = 10 * 1024 * 1024;
|
|
451
|
+
const str = (v) => typeof v === "string" ? v : "";
|
|
452
|
+
const bool = (v) => v === true || v === "true";
|
|
453
|
+
const list = (v) => v ? Array.isArray(v) ? v : [v] : [];
|
|
454
|
+
const clean = (text2, labels) => {
|
|
455
|
+
const r = checkPrompt(text2, labels);
|
|
456
|
+
if ("error" in r) throw new InputError(r.error);
|
|
457
|
+
return r.text;
|
|
458
|
+
};
|
|
459
|
+
const checkImage = (f) => {
|
|
460
|
+
if (!ALLOWED.includes(f.mimetype ?? "")) throw new InputError("Las imágenes deben ser PNG, JPG o WEBP.");
|
|
461
|
+
if (f.size > MAX_BYTES) throw new InputError("Cada imagen puede pesar hasta 10 MB.");
|
|
462
|
+
return f;
|
|
463
|
+
};
|
|
464
|
+
const parseGenerateInput = (fields, files) => {
|
|
465
|
+
const prompt = clean(str(fields.prompt));
|
|
466
|
+
const model = findModel(str(fields.model));
|
|
467
|
+
if (!model) throw new InputError("Modelo no disponible.");
|
|
468
|
+
const aspectRatio = str(fields.aspectRatio) || "1:1";
|
|
469
|
+
if (!model.aspectRatios.includes(aspectRatio)) throw new InputError(`Proporción no disponible para ${model.label}.`);
|
|
470
|
+
const references = list(files.references).map(checkImage);
|
|
471
|
+
if (references.length && model.maxReferences === 0) throw new InputError(`${model.label} no acepta imágenes de referencia.`);
|
|
472
|
+
if (references.length > model.maxReferences) throw new InputError(`Máximo ${model.maxReferences} imágenes de referencia con ${model.label}.`);
|
|
473
|
+
const size2 = str(fields.imageSize);
|
|
474
|
+
return {
|
|
475
|
+
prompt,
|
|
476
|
+
model,
|
|
477
|
+
aspectRatio,
|
|
478
|
+
imageSize: model.sizes.includes(size2) ? size2 : void 0,
|
|
479
|
+
safety: fields.safety === void 0 ? true : bool(fields.safety),
|
|
480
|
+
allowPeople: bool(fields.allowPeople),
|
|
481
|
+
grounding: model.grounding && bool(fields.grounding),
|
|
482
|
+
references
|
|
483
|
+
};
|
|
484
|
+
};
|
|
485
|
+
const parseEditInput = (fields, files) => {
|
|
486
|
+
const instruction = clean(str(fields.instruction), INSTRUCTION_LABELS);
|
|
487
|
+
const [image] = list(files.image);
|
|
488
|
+
if (!image) throw new InputError("Falta la imagen a editar.");
|
|
489
|
+
const model = editModelFor(str(fields.model) || void 0);
|
|
490
|
+
const max = Math.max(0, model.maxReferences - 1);
|
|
491
|
+
const references = list(files.references).map(checkImage);
|
|
492
|
+
if (references.length > max) throw new InputError(`Máximo ${max} elementos para el cambio con ${model.label}.`);
|
|
493
|
+
return {
|
|
494
|
+
instruction,
|
|
495
|
+
model,
|
|
496
|
+
image: checkImage(image),
|
|
497
|
+
references,
|
|
498
|
+
// Sin los campos (clientes anteriores a S4.13): con seguridad y sin excluir personas, como antes.
|
|
499
|
+
safety: fields.safety === void 0 ? true : bool(fields.safety),
|
|
500
|
+
allowPeople: fields.allowPeople === void 0 ? true : bool(fields.allowPeople),
|
|
501
|
+
aspectRatio: model.aspectRatios.includes(str(fields.aspectRatio)) ? str(fields.aspectRatio) : void 0
|
|
502
|
+
};
|
|
503
|
+
};
|
|
504
|
+
const fail$2 = (ctx, status, name2, message) => {
|
|
505
|
+
ctx.status = status;
|
|
506
|
+
ctx.body = { data: null, error: { status, name: name2, message } };
|
|
507
|
+
};
|
|
508
|
+
const imageStudio = ({ strapi }) => {
|
|
509
|
+
const studio = () => strapi.plugin("strapi-content-generator-gemini").service("image-studio");
|
|
510
|
+
const run = async (ctx, work) => {
|
|
511
|
+
try {
|
|
512
|
+
ctx.body = await work();
|
|
513
|
+
} catch (err) {
|
|
514
|
+
if (err instanceof InputError) return fail$2(ctx, 400, "BadRequestError", err.message);
|
|
515
|
+
if (err instanceof BlockedError) return fail$2(ctx, 422, "UnprocessableEntityError", err.message);
|
|
516
|
+
strapi.log.error(`[image-studio] ${err instanceof Error ? err.message : String(err)}`);
|
|
517
|
+
return fail$2(ctx, 502, "BadGatewayError", "El servicio de imágenes no respondió. Intenta de nuevo en un momento.");
|
|
253
518
|
}
|
|
254
|
-
}
|
|
519
|
+
};
|
|
520
|
+
return {
|
|
521
|
+
models: (ctx) => run(ctx, () => studio().models()),
|
|
522
|
+
generate: (ctx) => run(ctx, () => studio().generate(parseGenerateInput(ctx.request.body ?? {}, ctx.request.files ?? {}))),
|
|
523
|
+
edit: (ctx) => run(ctx, () => studio().edit(parseEditInput(ctx.request.body ?? {}, ctx.request.files ?? {}))),
|
|
524
|
+
expand: (ctx) => run(ctx, async () => {
|
|
525
|
+
const raw = typeof ctx.request.body?.prompt === "string" ? ctx.request.body.prompt : "";
|
|
526
|
+
const prompt = clean(raw, { label: "La idea", empty: "Escribe una idea para expandir." });
|
|
527
|
+
return { prompt: await studio().expand(prompt) };
|
|
528
|
+
})
|
|
529
|
+
};
|
|
530
|
+
};
|
|
531
|
+
const NAVY = "#1F2A44";
|
|
532
|
+
const RED = "#E4002B";
|
|
533
|
+
const TEAL = "#00C7B1";
|
|
534
|
+
const GREY = "#5B6473";
|
|
535
|
+
const PAPER = "#EEF1F5";
|
|
536
|
+
const WHITE = "#FFFFFF";
|
|
537
|
+
const WHITE_75 = "rgba(255,255,255,0.75)";
|
|
538
|
+
const WHITE_60 = "rgba(255,255,255,0.6)";
|
|
539
|
+
const WHITE_20 = "rgba(255,255,255,0.2)";
|
|
540
|
+
const BASE_TEMPLATES = [
|
|
255
541
|
{
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
542
|
+
id: "cuadrado_01",
|
|
543
|
+
name: "Cuadrado 01",
|
|
544
|
+
category: "Redes sociales",
|
|
545
|
+
tag: "1:1",
|
|
546
|
+
width: 1080,
|
|
547
|
+
height: 1080,
|
|
548
|
+
background: PAPER,
|
|
549
|
+
safeMargin: 80,
|
|
550
|
+
gridUnit: 60,
|
|
551
|
+
layers: [
|
|
552
|
+
{ id: "logo", type: "logo", label: "Logo", x: 80, y: 80, color: NAVY, logoScale: 1.1 },
|
|
553
|
+
{ id: "titulo", type: "text", label: "Título", x: 80, y: 280, w: 920, content: "Orquestación digital para empresas", fontSize: 90, fontWeight: 800, color: NAVY, font: "display", lineHeight: 1.08, letterSpacing: "-0.02em" },
|
|
554
|
+
{ id: "divider", type: "rect", label: "Divisor", x: 80, y: 530, w: 420, h: 3, color: RED },
|
|
555
|
+
{ id: "cuerpo", type: "text", label: "Cuerpo", x: 80, y: 580, w: 700, content: "29 años integrando, modernizando y operando los sistemas de las empresas en México.", fontSize: 36, fontWeight: 500, color: NAVY, lineHeight: 1.5 }
|
|
556
|
+
]
|
|
263
557
|
},
|
|
264
558
|
{
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
559
|
+
id: "cuadrado_dark",
|
|
560
|
+
name: "Cuadrado Dark",
|
|
561
|
+
category: "Redes sociales",
|
|
562
|
+
tag: "1:1",
|
|
563
|
+
width: 1080,
|
|
564
|
+
height: 1080,
|
|
565
|
+
background: NAVY,
|
|
566
|
+
safeMargin: 80,
|
|
567
|
+
gridUnit: 60,
|
|
568
|
+
layers: [
|
|
569
|
+
{ id: "accent_top", type: "rect", label: "Acento superior", x: 0, y: 0, w: 1080, h: 6, color: RED },
|
|
570
|
+
{ id: "watermark", type: "logo", label: "Marca de agua", x: 600, y: 700, color: WHITE, logoScale: 2.6, opacity: 0.1 },
|
|
571
|
+
{ id: "logo", type: "logo", label: "Logo", x: 80, y: 86, color: WHITE, logoScale: 1.1 },
|
|
572
|
+
{ id: "titulo", type: "text", label: "Título", x: 80, y: 280, w: 920, content: "Detectamos y resolvemos fallas antes de que lleguen a tu cliente", fontSize: 78, fontWeight: 800, color: WHITE, font: "display", lineHeight: 1.08, letterSpacing: "-0.02em" },
|
|
573
|
+
{ id: "divider", type: "rect", label: "Divisor", x: 80, y: 560, w: 360, h: 3, color: TEAL },
|
|
574
|
+
{ id: "cuerpo", type: "text", label: "Cuerpo", x: 80, y: 610, w: 700, content: "Observabilidad y operación continua para sistemas de misión crítica.", fontSize: 34, fontWeight: 500, color: WHITE_75, lineHeight: 1.5 }
|
|
575
|
+
]
|
|
272
576
|
},
|
|
273
577
|
{
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
578
|
+
id: "horizontal_01",
|
|
579
|
+
name: "Horizontal 01",
|
|
580
|
+
category: "Web / Blog",
|
|
581
|
+
tag: "16:9",
|
|
582
|
+
width: 1920,
|
|
583
|
+
height: 1080,
|
|
584
|
+
background: PAPER,
|
|
585
|
+
safeMargin: 100,
|
|
586
|
+
gridUnit: 80,
|
|
587
|
+
layers: [
|
|
588
|
+
{ id: "right_panel", type: "rect", label: "Panel derecho", x: 1056, y: 0, w: 864, h: 1080, color: NAVY },
|
|
589
|
+
{ id: "watermark", type: "logo", label: "Marca de agua", x: 1100, y: 200, color: WHITE, logoScale: 8, opacity: 0.08 },
|
|
590
|
+
{ id: "logo", type: "logo", label: "Logo", x: 100, y: 100, color: NAVY, logoScale: 1.3 },
|
|
591
|
+
{ id: "subtitulo", type: "text", label: "Subtítulo", x: 100, y: 600, w: 900, content: "Perspectivas para líderes de TI", fontSize: 28, fontWeight: 700, color: RED, textTransform: "uppercase", letterSpacing: "0.06em" },
|
|
592
|
+
{ id: "titulo", type: "text", label: "Título", x: 100, y: 660, w: 900, content: "Evolución por continuidad", fontSize: 96, fontWeight: 800, color: NAVY, font: "display", lineHeight: 1, letterSpacing: "-0.02em" },
|
|
593
|
+
{ id: "divider", type: "rect", label: "Divisor", x: 100, y: 880, w: 300, h: 4, color: NAVY },
|
|
594
|
+
{ id: "url", type: "text", label: "URL", x: 100, y: 990, w: 800, content: "interware.com.mx", fontSize: 22, fontWeight: 500, color: GREY },
|
|
595
|
+
{ id: "logo_right", type: "logo", label: "Logo derecho", x: 1700, y: 990, color: WHITE_60, logoScale: 1.5 }
|
|
596
|
+
]
|
|
281
597
|
},
|
|
282
598
|
{
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
599
|
+
id: "story_01",
|
|
600
|
+
name: "Story / Reels",
|
|
601
|
+
category: "Redes sociales",
|
|
602
|
+
tag: "9:16",
|
|
603
|
+
width: 1080,
|
|
604
|
+
height: 1920,
|
|
605
|
+
background: NAVY,
|
|
606
|
+
safeMargin: 80,
|
|
607
|
+
gridUnit: 80,
|
|
608
|
+
layers: [
|
|
609
|
+
{ id: "watermark", type: "logo", label: "Marca de agua", x: 700, y: -40, color: WHITE, logoScale: 7, opacity: 0.06, rotate: -15 },
|
|
610
|
+
{ id: "accent", type: "rect", label: "Acento superior", x: 0, y: 0, w: 1080, h: 8, color: TEAL },
|
|
611
|
+
{ id: "logo", type: "logo", label: "Logo", x: 80, y: 60, color: WHITE, logoScale: 1.1 },
|
|
612
|
+
{ id: "line", type: "rect", label: "Línea", x: 80, y: 672, w: 60, h: 5, color: TEAL },
|
|
613
|
+
{ id: "titulo", type: "text", label: "Título", x: 80, y: 720, w: 920, content: "Tu operación, orquestada", fontSize: 100, fontWeight: 800, color: WHITE, font: "display", lineHeight: 1.05, letterSpacing: "-0.02em" },
|
|
614
|
+
{ id: "cta", type: "badge", label: "CTA", x: 80, y: 1670, content: "Conoce más →", paddingX: 32, paddingY: 16, bg: WHITE, fontSize: 34, fontWeight: 700, color: NAVY }
|
|
615
|
+
]
|
|
290
616
|
},
|
|
291
617
|
{
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
618
|
+
id: "blog_hero",
|
|
619
|
+
name: "Blog Hero",
|
|
620
|
+
category: "Web / Blog",
|
|
621
|
+
tag: "~2:1",
|
|
622
|
+
width: 1200,
|
|
623
|
+
height: 630,
|
|
624
|
+
background: PAPER,
|
|
625
|
+
safeMargin: 72,
|
|
626
|
+
gridUnit: 60,
|
|
627
|
+
layers: [
|
|
628
|
+
{ id: "strip", type: "rect", label: "Franja izquierda", x: 0, y: 0, w: 8, h: 630, color: RED },
|
|
629
|
+
{ id: "logo", type: "logo", label: "Logo", x: 80, y: 72, color: NAVY, logoScale: 1 },
|
|
630
|
+
{ id: "categoria", type: "badge", label: "Categoría", x: 900, y: 72, content: "Infraestructura", paddingX: 18, paddingY: 8, bg: NAVY, fontSize: 22, fontWeight: 700, color: WHITE, textTransform: "uppercase", letterSpacing: "0.06em" },
|
|
631
|
+
{ id: "titulo", type: "text", label: "Título", x: 80, y: 300, w: 1040, content: "La deuda técnica también se paga en horas de operación", fontSize: 60, fontWeight: 800, color: NAVY, font: "display", lineHeight: 1.1, letterSpacing: "-0.02em" },
|
|
632
|
+
{ id: "divider", type: "rect", label: "Divisor", x: 80, y: 475, w: 200, h: 3, color: RED },
|
|
633
|
+
{ id: "autor", type: "text", label: "Autor", x: 80, y: 500, w: 800, content: "Por el equipo de InterWare", fontSize: 24, fontWeight: 600, color: GREY }
|
|
634
|
+
]
|
|
299
635
|
},
|
|
300
636
|
{
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
637
|
+
id: "linkedin_banner",
|
|
638
|
+
name: "LinkedIn Banner",
|
|
639
|
+
category: "LinkedIn",
|
|
640
|
+
tag: "4:1",
|
|
641
|
+
width: 1584,
|
|
642
|
+
height: 396,
|
|
643
|
+
background: NAVY,
|
|
644
|
+
safeMargin: 60,
|
|
645
|
+
gridUnit: 60,
|
|
646
|
+
layers: [
|
|
647
|
+
{ id: "watermark", type: "logo", label: "Marca de agua", x: 1100, y: -40, color: WHITE, logoScale: 9, opacity: 0.05 },
|
|
648
|
+
{ id: "strip", type: "rect", label: "Franja", x: 0, y: 0, w: 6, h: 396, color: TEAL, gradient: `linear-gradient(to bottom, ${TEAL}, ${NAVY})` },
|
|
649
|
+
{ id: "logo", type: "logo", label: "Logo", x: 60, y: 150, color: WHITE, logoScale: 1.4 },
|
|
650
|
+
{ id: "vdivider", type: "rect", label: "Divisor vertical", x: 320, y: 158, w: 2, h: 80, color: WHITE_20 },
|
|
651
|
+
{ id: "nombre", type: "text", label: "Nombre", x: 360, y: 140, w: 1100, content: "InterWare de México", fontSize: 44, fontWeight: 800, color: WHITE, font: "display", letterSpacing: "-0.01em" },
|
|
652
|
+
{ id: "tagline", type: "text", label: "Tagline", x: 360, y: 200, w: 1100, content: "Orquestación digital para empresas", fontSize: 26, fontWeight: 500, color: WHITE_60 }
|
|
653
|
+
]
|
|
308
654
|
}
|
|
309
655
|
];
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
656
|
+
new Set(BASE_TEMPLATES.map((t) => t.id));
|
|
657
|
+
const cleanPath = (path) => path.split("/").map((s) => s.trim()).filter(Boolean).join("/");
|
|
658
|
+
const parentOf = (path) => path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "";
|
|
659
|
+
const isUnder = (path, base) => path === base || path.startsWith(`${base}/`);
|
|
660
|
+
const renamePath = (path, from, to) => isUnder(path, from) ? to + path.slice(from.length) : path;
|
|
661
|
+
const folderTree = (paths) => {
|
|
662
|
+
const all3 = /* @__PURE__ */ new Set();
|
|
663
|
+
for (const p of paths.map(cleanPath).filter(Boolean)) {
|
|
664
|
+
let cur = p;
|
|
665
|
+
while (cur) {
|
|
666
|
+
all3.add(cur);
|
|
667
|
+
cur = parentOf(cur);
|
|
318
668
|
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
669
|
+
}
|
|
670
|
+
return [...all3].sort((a, b) => a.localeCompare(b, "es"));
|
|
671
|
+
};
|
|
672
|
+
class TemplateInputError extends Error {
|
|
673
|
+
}
|
|
674
|
+
const LAYER_TYPES = ["text", "list", "quote", "rect", "shape", "badge", "logo", "image", "icon", "avatar", "qr"];
|
|
675
|
+
const MAX_LAYERS = 200;
|
|
676
|
+
const fail$1 = (message) => {
|
|
677
|
+
throw new TemplateInputError(message);
|
|
678
|
+
};
|
|
679
|
+
const hasDataUrl = (value) => {
|
|
680
|
+
if (typeof value === "string") return value.startsWith("data:");
|
|
681
|
+
if (Array.isArray(value)) return value.some(hasDataUrl);
|
|
682
|
+
if (value && typeof value === "object") return Object.values(value).some(hasDataUrl);
|
|
683
|
+
return false;
|
|
684
|
+
};
|
|
685
|
+
const name = (v) => {
|
|
686
|
+
const n = typeof v === "string" ? v.trim() : "";
|
|
687
|
+
if (!n || n.length > 120) fail$1("El nombre debe tener entre 1 y 120 caracteres.");
|
|
688
|
+
return n;
|
|
689
|
+
};
|
|
690
|
+
const size = (v) => {
|
|
691
|
+
if (!Number.isInteger(v) || v < 100 || v > 4e3) fail$1("Las medidas deben ser enteros de 100 a 4000 px.");
|
|
692
|
+
return v;
|
|
693
|
+
};
|
|
694
|
+
const nonNegative = (v, label) => {
|
|
695
|
+
if (typeof v !== "number" || !Number.isFinite(v) || v < 0) fail$1(`${label} debe ser un número positivo.`);
|
|
696
|
+
return v;
|
|
697
|
+
};
|
|
698
|
+
const layers = (v) => {
|
|
699
|
+
if (!Array.isArray(v) || v.length > MAX_LAYERS) fail$1(`Las capas deben ser una lista de hasta ${MAX_LAYERS}.`);
|
|
700
|
+
v.forEach((l, i) => {
|
|
701
|
+
const layer = l ?? {};
|
|
702
|
+
if (typeof layer.id !== "string" || !layer.id) fail$1(`La capa ${i + 1} no tiene id.`);
|
|
703
|
+
if (!LAYER_TYPES.includes(layer.type)) fail$1(`La capa ${i + 1} tiene un tipo desconocido.`);
|
|
704
|
+
if (typeof layer.x !== "number" || typeof layer.y !== "number") fail$1(`La capa ${i + 1} no tiene posición.`);
|
|
705
|
+
});
|
|
706
|
+
if (hasDataUrl(v)) fail$1("Las imágenes deben guardarse en la Media Library, no dentro del template.");
|
|
707
|
+
return v;
|
|
708
|
+
};
|
|
709
|
+
const text = (v, fallback) => typeof v === "string" ? v : fallback;
|
|
710
|
+
const validateTemplate = (input) => {
|
|
711
|
+
const t = input ?? {};
|
|
712
|
+
const out = {
|
|
713
|
+
name: name(t.name),
|
|
714
|
+
folder: cleanPath(text(t.folder, "")),
|
|
715
|
+
width: size(t.width),
|
|
716
|
+
height: size(t.height),
|
|
717
|
+
background: text(t.background, "#FFFFFF"),
|
|
718
|
+
safeMargin: nonNegative(t.safeMargin ?? 0, "El margen seguro"),
|
|
719
|
+
gridUnit: nonNegative(t.gridUnit ?? 60, "La cuadrícula"),
|
|
720
|
+
layers: layers(t.layers)
|
|
721
|
+
};
|
|
722
|
+
if (typeof t.baseId === "string" && t.baseId) out.baseId = t.baseId;
|
|
723
|
+
return out;
|
|
724
|
+
};
|
|
725
|
+
const validateTemplatePatch = (input) => {
|
|
726
|
+
const t = input ?? {};
|
|
727
|
+
const out = {};
|
|
728
|
+
if ("name" in t) out.name = name(t.name);
|
|
729
|
+
if ("folder" in t) out.folder = cleanPath(text(t.folder, ""));
|
|
730
|
+
if ("width" in t) out.width = size(t.width);
|
|
731
|
+
if ("height" in t) out.height = size(t.height);
|
|
732
|
+
if ("background" in t) out.background = text(t.background, "#FFFFFF");
|
|
733
|
+
if ("safeMargin" in t) out.safeMargin = nonNegative(t.safeMargin, "El margen seguro");
|
|
734
|
+
if ("gridUnit" in t) out.gridUnit = nonNegative(t.gridUnit, "La cuadrícula");
|
|
735
|
+
if ("layers" in t) out.layers = layers(t.layers);
|
|
736
|
+
if (!Object.keys(out).length) fail$1("Nada que actualizar.");
|
|
737
|
+
return out;
|
|
738
|
+
};
|
|
739
|
+
const TEMPLATE_UID = "plugin::strapi-content-generator-gemini.template";
|
|
740
|
+
const FOLDERS_KEY = "TEMPLATE_FOLDERS";
|
|
741
|
+
class TemplateNotFoundError extends Error {
|
|
742
|
+
}
|
|
743
|
+
const FIELDS = ["name", "folder", "width", "height", "background", "safeMargin", "gridUnit", "layers", "baseId", "replacesBase"];
|
|
744
|
+
const BASE_IDS = new Set(BASE_TEMPLATES.map((t) => t.id));
|
|
745
|
+
const checkBaseId = (baseId) => {
|
|
746
|
+
if (typeof baseId !== "string" || !BASE_IDS.has(baseId)) throw new TemplateInputError("Plantilla base desconocida.");
|
|
747
|
+
return baseId;
|
|
748
|
+
};
|
|
749
|
+
const toStored = (d) => {
|
|
750
|
+
const out = { documentId: d.documentId, updatedAt: d.updatedAt };
|
|
751
|
+
for (const f of FIELDS) if (d[f] !== void 0 && d[f] !== null) out[f] = d[f];
|
|
752
|
+
out.folder = typeof d.folder === "string" ? d.folder : "";
|
|
753
|
+
return out;
|
|
754
|
+
};
|
|
755
|
+
const createTemplatesService = (docs, store) => {
|
|
756
|
+
const all3 = async () => (await docs.findMany({})).map(toStored);
|
|
757
|
+
const storedFolders = async () => {
|
|
758
|
+
const v = await store.get({ key: FOLDERS_KEY });
|
|
759
|
+
return Array.isArray(v) ? v : [];
|
|
760
|
+
};
|
|
761
|
+
const saveFolders = (folders) => store.set({ key: FOLDERS_KEY, value: folderTree(folders) });
|
|
762
|
+
const tree = async () => folderTree([...await storedFolders(), ...(await all3()).map((t) => t.folder)]);
|
|
763
|
+
const mustExist = async (documentId) => {
|
|
764
|
+
const d = await docs.findOne({ documentId });
|
|
765
|
+
if (!d) throw new TemplateNotFoundError("El template no existe o fue eliminado.");
|
|
766
|
+
return d;
|
|
767
|
+
};
|
|
768
|
+
const moveTemplates = async (path, to) => {
|
|
769
|
+
for (const t of await all3()) {
|
|
770
|
+
if (isUnder(t.folder, path)) await docs.update({ documentId: t.documentId, data: { folder: to(t.folder) } });
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
return {
|
|
774
|
+
async list() {
|
|
775
|
+
return (await all3()).sort((a, b) => a.name.localeCompare(b.name, "es", { sensitivity: "base" }));
|
|
776
|
+
},
|
|
777
|
+
async findOne(documentId) {
|
|
778
|
+
return toStored(await mustExist(documentId));
|
|
779
|
+
},
|
|
780
|
+
async create(input) {
|
|
781
|
+
return toStored(await docs.create({ data: validateTemplate(input) }));
|
|
782
|
+
},
|
|
783
|
+
async update(documentId, patch) {
|
|
784
|
+
const data = validateTemplatePatch(patch);
|
|
785
|
+
await mustExist(documentId);
|
|
786
|
+
return toStored(await docs.update({ documentId, data }));
|
|
787
|
+
},
|
|
788
|
+
async remove(documentId) {
|
|
789
|
+
await mustExist(documentId);
|
|
790
|
+
await docs.delete({ documentId });
|
|
791
|
+
},
|
|
792
|
+
/**
|
|
793
|
+
* Guarda la versión editada de una plantilla base (S4.15): la crea la primera vez y después la
|
|
794
|
+
* actualiza. Vive en la raíz y conserva la base como origen.
|
|
795
|
+
*/
|
|
796
|
+
async saveBase(baseId, input) {
|
|
797
|
+
const id = checkBaseId(baseId);
|
|
798
|
+
const data = { ...validateTemplate(input), folder: "", baseId: id, replacesBase: id };
|
|
799
|
+
const current = (await all3()).find((t) => t.replacesBase === id);
|
|
800
|
+
return toStored(current ? await docs.update({ documentId: current.documentId, data }) : await docs.create({ data }));
|
|
801
|
+
},
|
|
802
|
+
/** Vuelve a la versión de InterWare: borra la editada, si existe. */
|
|
803
|
+
async restoreBase(baseId) {
|
|
804
|
+
const id = checkBaseId(baseId);
|
|
805
|
+
const current = (await all3()).find((t) => t.replacesBase === id);
|
|
806
|
+
if (current) await docs.delete({ documentId: current.documentId });
|
|
807
|
+
},
|
|
808
|
+
folders: tree,
|
|
809
|
+
async createFolder(path) {
|
|
810
|
+
const p = cleanPath(typeof path === "string" ? path : "");
|
|
811
|
+
if (!p) throw new TemplateInputError("Escribe el nombre de la carpeta.");
|
|
812
|
+
if ((await tree()).includes(p)) throw new TemplateInputError("Ya existe una carpeta con ese nombre.");
|
|
813
|
+
await saveFolders([...await storedFolders(), p]);
|
|
814
|
+
return tree();
|
|
815
|
+
},
|
|
816
|
+
async renameFolder(from, to) {
|
|
817
|
+
const src = cleanPath(typeof from === "string" ? from : "");
|
|
818
|
+
const dst = cleanPath(typeof to === "string" ? to : "");
|
|
819
|
+
if (!src || !dst) throw new TemplateInputError("Indica la carpeta y su nombre nuevo.");
|
|
820
|
+
if (src === dst) return tree();
|
|
821
|
+
const current = await tree();
|
|
822
|
+
if (!current.includes(src)) throw new TemplateInputError("La carpeta no existe.");
|
|
823
|
+
if (current.includes(dst) || isUnder(dst, src)) throw new TemplateInputError("Ya existe una carpeta con ese nombre.");
|
|
824
|
+
await saveFolders(current.map((p) => renamePath(p, src, dst)));
|
|
825
|
+
await moveTemplates(src, (f) => renamePath(f, src, dst));
|
|
826
|
+
return tree();
|
|
827
|
+
},
|
|
828
|
+
async deleteFolder(path) {
|
|
829
|
+
const p = cleanPath(typeof path === "string" ? path : "");
|
|
830
|
+
if (!p) throw new TemplateInputError("No se puede eliminar la raíz.");
|
|
831
|
+
const target = parentOf(p);
|
|
832
|
+
await saveFolders((await tree()).filter((f) => !isUnder(f, p)));
|
|
833
|
+
await moveTemplates(p, () => target);
|
|
834
|
+
return tree();
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
};
|
|
838
|
+
const templates$1 = ({ strapi }) => {
|
|
839
|
+
const docs = () => strapi.documents(TEMPLATE_UID);
|
|
840
|
+
const store = () => strapi.store({ type: "plugin", name: "strapi-content-generator-gemini" });
|
|
841
|
+
return createTemplatesService(
|
|
842
|
+
{
|
|
843
|
+
findMany: (p) => docs().findMany(p),
|
|
844
|
+
findOne: (p) => docs().findOne(p),
|
|
845
|
+
create: (p) => docs().create(p),
|
|
846
|
+
update: (p) => docs().update(p),
|
|
847
|
+
delete: (p) => docs().delete(p)
|
|
848
|
+
},
|
|
849
|
+
{ get: (p) => store().get(p), set: (p) => store().set(p) }
|
|
850
|
+
);
|
|
851
|
+
};
|
|
852
|
+
const fail = (ctx, status, name2, message) => {
|
|
853
|
+
ctx.status = status;
|
|
854
|
+
ctx.body = { data: null, error: { status, name: name2, message } };
|
|
855
|
+
};
|
|
856
|
+
const templates = ({ strapi }) => {
|
|
857
|
+
const svc = () => strapi.plugin("strapi-content-generator-gemini").service("templates");
|
|
858
|
+
const run = async (ctx, work, status = 200) => {
|
|
859
|
+
try {
|
|
860
|
+
ctx.body = await work();
|
|
861
|
+
ctx.status = status;
|
|
862
|
+
} catch (err) {
|
|
863
|
+
if (err instanceof TemplateInputError) return fail(ctx, 400, "BadRequestError", err.message);
|
|
864
|
+
if (err instanceof TemplateNotFoundError) return fail(ctx, 404, "NotFoundError", err.message);
|
|
865
|
+
strapi.log.error(`[templates] ${err instanceof Error ? err.message : String(err)}`);
|
|
866
|
+
return fail(ctx, 500, "InternalServerError", "No se pudo completar la operación con los templates.");
|
|
327
867
|
}
|
|
868
|
+
};
|
|
869
|
+
const body = (ctx) => ctx.request.body ?? {};
|
|
870
|
+
return {
|
|
871
|
+
list: (ctx) => run(ctx, async () => ({ templates: await svc().list() })),
|
|
872
|
+
create: (ctx) => run(ctx, () => svc().create(body(ctx)), 201),
|
|
873
|
+
findOne: (ctx) => run(ctx, () => svc().findOne(ctx.params.documentId)),
|
|
874
|
+
update: (ctx) => run(ctx, () => svc().update(ctx.params.documentId, body(ctx))),
|
|
875
|
+
remove: (ctx) => run(ctx, async () => {
|
|
876
|
+
await svc().remove(ctx.params.documentId);
|
|
877
|
+
return { ok: true };
|
|
878
|
+
}),
|
|
879
|
+
saveBase: (ctx) => run(ctx, () => svc().saveBase(ctx.params.baseId, body(ctx))),
|
|
880
|
+
restoreBase: (ctx) => run(ctx, async () => {
|
|
881
|
+
await svc().restoreBase(ctx.params.baseId);
|
|
882
|
+
return { ok: true };
|
|
883
|
+
}),
|
|
884
|
+
folders: (ctx) => run(ctx, async () => ({ folders: await svc().folders() })),
|
|
885
|
+
createFolder: (ctx) => run(ctx, async () => ({ folders: await svc().createFolder(body(ctx).path) })),
|
|
886
|
+
renameFolder: (ctx) => run(ctx, async () => ({ folders: await svc().renameFolder(body(ctx).from, body(ctx).to) })),
|
|
887
|
+
deleteFolder: (ctx) => run(ctx, async () => ({ folders: await svc().deleteFolder(body(ctx).path) }))
|
|
888
|
+
};
|
|
889
|
+
};
|
|
890
|
+
const controllers = {
|
|
891
|
+
controller,
|
|
892
|
+
config: config$1,
|
|
893
|
+
"image-studio": imageStudio,
|
|
894
|
+
templates
|
|
895
|
+
};
|
|
896
|
+
const middlewares = {};
|
|
897
|
+
const policies = {};
|
|
898
|
+
const ACCESS_ACTION = "plugin::strapi-content-generator-gemini.access";
|
|
899
|
+
const ADMIN_ACCESS_POLICIES = [
|
|
900
|
+
"admin::isAuthenticatedAdmin",
|
|
901
|
+
{
|
|
902
|
+
name: "admin::hasPermissions",
|
|
903
|
+
config: { actions: [ACCESS_ACTION] }
|
|
328
904
|
}
|
|
329
905
|
];
|
|
906
|
+
const config = { policies: ADMIN_ACCESS_POLICIES };
|
|
907
|
+
const admin = [
|
|
908
|
+
{ method: "GET", path: "/posts", handler: "controller.getArticles", config },
|
|
909
|
+
{ method: "GET", path: "/categories", handler: "controller.getCategories", config },
|
|
910
|
+
{ method: "GET", path: "/users", handler: "controller.getUsers", config },
|
|
911
|
+
{ method: "POST", path: "/download-file", handler: "controller.downloadFile", config },
|
|
912
|
+
{ method: "POST", path: "/generate-article", handler: "controller.generateArticle", config },
|
|
913
|
+
{ method: "POST", path: "/generate-image", handler: "controller.generateImageForArticle", config },
|
|
914
|
+
{ method: "GET", path: "/image-studio/models", handler: "image-studio.models", config },
|
|
915
|
+
{ method: "POST", path: "/image-studio/generate", handler: "image-studio.generate", config },
|
|
916
|
+
{ method: "POST", path: "/image-studio/edit", handler: "image-studio.edit", config },
|
|
917
|
+
{ method: "POST", path: "/image-studio/expand", handler: "image-studio.expand", config },
|
|
918
|
+
{ method: "POST", path: "/generate-video-with-scenes", handler: "controller.generateVideo", config },
|
|
919
|
+
{ method: "POST", path: "/publish-linkedin", handler: "controller.publishToLinkedIn", config },
|
|
920
|
+
{ method: "POST", path: "/publish-facebook", handler: "controller.publishToFacebook", config },
|
|
921
|
+
{ method: "GET", path: "/templates", handler: "templates.list", config },
|
|
922
|
+
{ method: "POST", path: "/templates", handler: "templates.create", config },
|
|
923
|
+
{ method: "GET", path: "/templates/:documentId", handler: "templates.findOne", config },
|
|
924
|
+
{ method: "PUT", path: "/templates/:documentId", handler: "templates.update", config },
|
|
925
|
+
{ method: "DELETE", path: "/templates/:documentId", handler: "templates.remove", config },
|
|
926
|
+
{ method: "PUT", path: "/templates/base/:baseId", handler: "templates.saveBase", config },
|
|
927
|
+
{ method: "DELETE", path: "/templates/base/:baseId", handler: "templates.restoreBase", config },
|
|
928
|
+
{ method: "GET", path: "/template-folders", handler: "templates.folders", config },
|
|
929
|
+
{ method: "POST", path: "/template-folders", handler: "templates.createFolder", config },
|
|
930
|
+
{ method: "POST", path: "/template-folders/rename", handler: "templates.renameFolder", config },
|
|
931
|
+
{ method: "POST", path: "/template-folders/delete", handler: "templates.deleteFolder", config },
|
|
932
|
+
{ method: "GET", path: "/config", handler: "config.get", config },
|
|
933
|
+
{ method: "POST", path: "/config", handler: "config.set", config },
|
|
934
|
+
{ method: "DELETE", path: "/config/vertex", handler: "config.removeVertex", config }
|
|
935
|
+
];
|
|
936
|
+
const contentApi = [];
|
|
330
937
|
const routes = {
|
|
331
938
|
"content-api": {
|
|
332
939
|
type: "content-api",
|
|
@@ -345,9 +952,26 @@ function bind(fn, thisArg) {
|
|
|
345
952
|
const { toString } = Object.prototype;
|
|
346
953
|
const { getPrototypeOf } = Object;
|
|
347
954
|
const { iterator, toStringTag } = Symbol;
|
|
955
|
+
const hasOwnProperty = (({ hasOwnProperty: hasOwnProperty2 }) => (obj, prop) => hasOwnProperty2.call(obj, prop))(Object.prototype);
|
|
956
|
+
const hasOwnInPrototypeChain = (thing, prop) => {
|
|
957
|
+
let obj = thing;
|
|
958
|
+
const seen = [];
|
|
959
|
+
while (obj != null && obj !== Object.prototype) {
|
|
960
|
+
if (seen.indexOf(obj) !== -1) {
|
|
961
|
+
return false;
|
|
962
|
+
}
|
|
963
|
+
seen.push(obj);
|
|
964
|
+
if (hasOwnProperty(obj, prop)) {
|
|
965
|
+
return true;
|
|
966
|
+
}
|
|
967
|
+
obj = getPrototypeOf(obj);
|
|
968
|
+
}
|
|
969
|
+
return false;
|
|
970
|
+
};
|
|
971
|
+
const getSafeProp = (obj, prop) => obj != null && hasOwnInPrototypeChain(obj, prop) ? obj[prop] : void 0;
|
|
348
972
|
const kindOf = /* @__PURE__ */ ((cache) => (thing) => {
|
|
349
|
-
const
|
|
350
|
-
return cache[
|
|
973
|
+
const str2 = toString.call(thing);
|
|
974
|
+
return cache[str2] || (cache[str2] = str2.slice(8, -1).toLowerCase());
|
|
351
975
|
})(/* @__PURE__ */ Object.create(null));
|
|
352
976
|
const kindOfTest = (type) => {
|
|
353
977
|
type = type.toLowerCase();
|
|
@@ -375,11 +999,14 @@ const isNumber = typeOfTest("number");
|
|
|
375
999
|
const isObject = (thing) => thing !== null && typeof thing === "object";
|
|
376
1000
|
const isBoolean = (thing) => thing === true || thing === false;
|
|
377
1001
|
const isPlainObject = (val) => {
|
|
378
|
-
if (
|
|
1002
|
+
if (!isObject(val)) {
|
|
379
1003
|
return false;
|
|
380
1004
|
}
|
|
381
1005
|
const prototype2 = getPrototypeOf(val);
|
|
382
|
-
return (prototype2 === null || prototype2 === Object.prototype ||
|
|
1006
|
+
return (prototype2 === null || prototype2 === Object.prototype || getPrototypeOf(prototype2) === null) && // Treat any genuine (non-Object.prototype-polluted) Symbol.toStringTag or
|
|
1007
|
+
// Symbol.iterator as evidence the value is a tagged/iterable type rather
|
|
1008
|
+
// than a plain object, while ignoring keys injected onto Object.prototype.
|
|
1009
|
+
!hasOwnInPrototypeChain(val, toStringTag) && !hasOwnInPrototypeChain(val, iterator);
|
|
383
1010
|
};
|
|
384
1011
|
const isEmptyObject = (val) => {
|
|
385
1012
|
if (!isObject(val) || isBuffer(val)) {
|
|
@@ -393,17 +1020,42 @@ const isEmptyObject = (val) => {
|
|
|
393
1020
|
};
|
|
394
1021
|
const isDate = kindOfTest("Date");
|
|
395
1022
|
const isFile = kindOfTest("File");
|
|
1023
|
+
const isReactNativeBlob = (value) => {
|
|
1024
|
+
return !!(value && typeof value.uri !== "undefined");
|
|
1025
|
+
};
|
|
1026
|
+
const isReactNative = (formData) => formData && typeof formData.getParts !== "undefined";
|
|
396
1027
|
const isBlob = kindOfTest("Blob");
|
|
397
1028
|
const isFileList = kindOfTest("FileList");
|
|
398
1029
|
const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
|
|
1030
|
+
function getGlobal() {
|
|
1031
|
+
if (typeof globalThis !== "undefined") return globalThis;
|
|
1032
|
+
if (typeof self !== "undefined") return self;
|
|
1033
|
+
if (typeof window !== "undefined") return window;
|
|
1034
|
+
if (typeof global !== "undefined") return global;
|
|
1035
|
+
return {};
|
|
1036
|
+
}
|
|
1037
|
+
const G = getGlobal();
|
|
1038
|
+
const FormDataCtor = typeof G.FormData !== "undefined" ? G.FormData : void 0;
|
|
399
1039
|
const isFormData = (thing) => {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
1040
|
+
if (!thing) return false;
|
|
1041
|
+
if (FormDataCtor && thing instanceof FormDataCtor) return true;
|
|
1042
|
+
const proto = getPrototypeOf(thing);
|
|
1043
|
+
if (!proto || proto === Object.prototype) return false;
|
|
1044
|
+
if (!isFunction$1(thing.append)) return false;
|
|
1045
|
+
const kind = kindOf(thing);
|
|
1046
|
+
return kind === "formdata" || // detect form-data instance
|
|
1047
|
+
kind === "object" && isFunction$1(thing.toString) && thing.toString() === "[object FormData]";
|
|
403
1048
|
};
|
|
404
1049
|
const isURLSearchParams = kindOfTest("URLSearchParams");
|
|
405
|
-
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
|
406
|
-
|
|
1050
|
+
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
|
1051
|
+
"ReadableStream",
|
|
1052
|
+
"Request",
|
|
1053
|
+
"Response",
|
|
1054
|
+
"Headers"
|
|
1055
|
+
].map(kindOfTest);
|
|
1056
|
+
const trim = (str2) => {
|
|
1057
|
+
return str2.trim ? str2.trim() : str2.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "");
|
|
1058
|
+
};
|
|
407
1059
|
function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
|
408
1060
|
if (obj === null || typeof obj === "undefined") {
|
|
409
1061
|
return;
|
|
@@ -451,13 +1103,17 @@ const _global = (() => {
|
|
|
451
1103
|
return typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : global;
|
|
452
1104
|
})();
|
|
453
1105
|
const isContextDefined = (context) => !isUndefined(context) && context !== _global;
|
|
454
|
-
function merge() {
|
|
1106
|
+
function merge(...objs) {
|
|
455
1107
|
const { caseless, skipUndefined } = isContextDefined(this) && this || {};
|
|
456
1108
|
const result = {};
|
|
457
1109
|
const assignValue = (val, key) => {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
1110
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1113
|
+
const targetKey = caseless && typeof key === "string" && findKey(result, key) || key;
|
|
1114
|
+
const existing = hasOwnProperty(result, targetKey) ? result[targetKey] : void 0;
|
|
1115
|
+
if (isPlainObject(existing) && isPlainObject(val)) {
|
|
1116
|
+
result[targetKey] = merge(existing, val);
|
|
461
1117
|
} else if (isPlainObject(val)) {
|
|
462
1118
|
result[targetKey] = merge({}, val);
|
|
463
1119
|
} else if (isArray(val)) {
|
|
@@ -466,19 +1122,51 @@ function merge() {
|
|
|
466
1122
|
result[targetKey] = val;
|
|
467
1123
|
}
|
|
468
1124
|
};
|
|
469
|
-
for (let i = 0, l =
|
|
470
|
-
|
|
1125
|
+
for (let i = 0, l = objs.length; i < l; i++) {
|
|
1126
|
+
const source = objs[i];
|
|
1127
|
+
if (!source || isBuffer(source)) {
|
|
1128
|
+
continue;
|
|
1129
|
+
}
|
|
1130
|
+
forEach(source, assignValue);
|
|
1131
|
+
if (typeof source !== "object" || isArray(source)) {
|
|
1132
|
+
continue;
|
|
1133
|
+
}
|
|
1134
|
+
const symbols = Object.getOwnPropertySymbols(source);
|
|
1135
|
+
for (let j = 0; j < symbols.length; j++) {
|
|
1136
|
+
const symbol = symbols[j];
|
|
1137
|
+
if (propertyIsEnumerable.call(source, symbol)) {
|
|
1138
|
+
assignValue(source[symbol], symbol);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
471
1141
|
}
|
|
472
1142
|
return result;
|
|
473
1143
|
}
|
|
474
1144
|
const extend = (a, b, thisArg, { allOwnKeys } = {}) => {
|
|
475
|
-
forEach(
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
1145
|
+
forEach(
|
|
1146
|
+
b,
|
|
1147
|
+
(val, key) => {
|
|
1148
|
+
if (thisArg && isFunction$1(val)) {
|
|
1149
|
+
Object.defineProperty(a, key, {
|
|
1150
|
+
// Null-proto descriptor so a polluted Object.prototype.get cannot
|
|
1151
|
+
// hijack defineProperty's accessor-vs-data resolution.
|
|
1152
|
+
__proto__: null,
|
|
1153
|
+
value: bind(val, thisArg),
|
|
1154
|
+
writable: true,
|
|
1155
|
+
enumerable: true,
|
|
1156
|
+
configurable: true
|
|
1157
|
+
});
|
|
1158
|
+
} else {
|
|
1159
|
+
Object.defineProperty(a, key, {
|
|
1160
|
+
__proto__: null,
|
|
1161
|
+
value: val,
|
|
1162
|
+
writable: true,
|
|
1163
|
+
enumerable: true,
|
|
1164
|
+
configurable: true
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
},
|
|
1168
|
+
{ allOwnKeys }
|
|
1169
|
+
);
|
|
482
1170
|
return a;
|
|
483
1171
|
};
|
|
484
1172
|
const stripBOM = (content) => {
|
|
@@ -487,10 +1175,17 @@ const stripBOM = (content) => {
|
|
|
487
1175
|
}
|
|
488
1176
|
return content;
|
|
489
1177
|
};
|
|
490
|
-
const inherits = (constructor, superConstructor, props,
|
|
491
|
-
constructor.prototype = Object.create(superConstructor.prototype,
|
|
492
|
-
constructor.prototype
|
|
1178
|
+
const inherits = (constructor, superConstructor, props, descriptors) => {
|
|
1179
|
+
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
|
1180
|
+
Object.defineProperty(constructor.prototype, "constructor", {
|
|
1181
|
+
__proto__: null,
|
|
1182
|
+
value: constructor,
|
|
1183
|
+
writable: true,
|
|
1184
|
+
enumerable: false,
|
|
1185
|
+
configurable: true
|
|
1186
|
+
});
|
|
493
1187
|
Object.defineProperty(constructor, "super", {
|
|
1188
|
+
__proto__: null,
|
|
494
1189
|
value: superConstructor.prototype
|
|
495
1190
|
});
|
|
496
1191
|
props && Object.assign(constructor.prototype, props);
|
|
@@ -516,13 +1211,13 @@ const toFlatObject = (sourceObj, destObj, filter2, propFilter) => {
|
|
|
516
1211
|
} while (sourceObj && (!filter2 || filter2(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
|
517
1212
|
return destObj;
|
|
518
1213
|
};
|
|
519
|
-
const endsWith = (
|
|
520
|
-
|
|
521
|
-
if (position === void 0 || position >
|
|
522
|
-
position =
|
|
1214
|
+
const endsWith = (str2, searchString, position) => {
|
|
1215
|
+
str2 = String(str2);
|
|
1216
|
+
if (position === void 0 || position > str2.length) {
|
|
1217
|
+
position = str2.length;
|
|
523
1218
|
}
|
|
524
1219
|
position -= searchString.length;
|
|
525
|
-
const lastIndex =
|
|
1220
|
+
const lastIndex = str2.indexOf(searchString, position);
|
|
526
1221
|
return lastIndex !== -1 && lastIndex === position;
|
|
527
1222
|
};
|
|
528
1223
|
const toArray = (thing) => {
|
|
@@ -550,42 +1245,39 @@ const forEachEntry = (obj, fn) => {
|
|
|
550
1245
|
fn.call(obj, pair[0], pair[1]);
|
|
551
1246
|
}
|
|
552
1247
|
};
|
|
553
|
-
const matchAll = (regExp,
|
|
1248
|
+
const matchAll = (regExp, str2) => {
|
|
554
1249
|
let matches;
|
|
555
1250
|
const arr = [];
|
|
556
|
-
while ((matches = regExp.exec(
|
|
1251
|
+
while ((matches = regExp.exec(str2)) !== null) {
|
|
557
1252
|
arr.push(matches);
|
|
558
1253
|
}
|
|
559
1254
|
return arr;
|
|
560
1255
|
};
|
|
561
1256
|
const isHTMLForm = kindOfTest("HTMLFormElement");
|
|
562
|
-
const toCamelCase = (
|
|
563
|
-
return
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
return p1.toUpperCase() + p2;
|
|
567
|
-
}
|
|
568
|
-
);
|
|
1257
|
+
const toCamelCase = (str2) => {
|
|
1258
|
+
return str2.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function replacer(m, p1, p2) {
|
|
1259
|
+
return p1.toUpperCase() + p2;
|
|
1260
|
+
});
|
|
569
1261
|
};
|
|
570
|
-
const
|
|
1262
|
+
const { propertyIsEnumerable } = Object.prototype;
|
|
571
1263
|
const isRegExp = kindOfTest("RegExp");
|
|
572
1264
|
const reduceDescriptors = (obj, reducer) => {
|
|
573
|
-
const
|
|
1265
|
+
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
|
574
1266
|
const reducedDescriptors = {};
|
|
575
|
-
forEach(
|
|
1267
|
+
forEach(descriptors, (descriptor, name2) => {
|
|
576
1268
|
let ret;
|
|
577
|
-
if ((ret = reducer(descriptor,
|
|
578
|
-
reducedDescriptors[
|
|
1269
|
+
if ((ret = reducer(descriptor, name2, obj)) !== false) {
|
|
1270
|
+
reducedDescriptors[name2] = ret || descriptor;
|
|
579
1271
|
}
|
|
580
1272
|
});
|
|
581
1273
|
Object.defineProperties(obj, reducedDescriptors);
|
|
582
1274
|
};
|
|
583
1275
|
const freezeMethods = (obj) => {
|
|
584
|
-
reduceDescriptors(obj, (descriptor,
|
|
585
|
-
if (isFunction$1(obj) && ["arguments", "caller", "callee"].
|
|
1276
|
+
reduceDescriptors(obj, (descriptor, name2) => {
|
|
1277
|
+
if (isFunction$1(obj) && ["arguments", "caller", "callee"].includes(name2)) {
|
|
586
1278
|
return false;
|
|
587
1279
|
}
|
|
588
|
-
const value = obj[
|
|
1280
|
+
const value = obj[name2];
|
|
589
1281
|
if (!isFunction$1(value)) return;
|
|
590
1282
|
descriptor.enumerable = false;
|
|
591
1283
|
if ("writable" in descriptor) {
|
|
@@ -594,7 +1286,7 @@ const freezeMethods = (obj) => {
|
|
|
594
1286
|
}
|
|
595
1287
|
if (!descriptor.set) {
|
|
596
1288
|
descriptor.set = () => {
|
|
597
|
-
throw Error("Can not rewrite read-only method '" +
|
|
1289
|
+
throw Error("Can not rewrite read-only method '" + name2 + "'");
|
|
598
1290
|
};
|
|
599
1291
|
}
|
|
600
1292
|
});
|
|
@@ -618,29 +1310,29 @@ function isSpecCompliantForm(thing) {
|
|
|
618
1310
|
return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === "FormData" && thing[iterator]);
|
|
619
1311
|
}
|
|
620
1312
|
const toJSONObject = (obj) => {
|
|
621
|
-
const
|
|
622
|
-
const visit = (source
|
|
1313
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
1314
|
+
const visit = (source) => {
|
|
623
1315
|
if (isObject(source)) {
|
|
624
|
-
if (
|
|
1316
|
+
if (visited.has(source)) {
|
|
625
1317
|
return;
|
|
626
1318
|
}
|
|
627
1319
|
if (isBuffer(source)) {
|
|
628
1320
|
return source;
|
|
629
1321
|
}
|
|
630
1322
|
if (!("toJSON" in source)) {
|
|
631
|
-
|
|
1323
|
+
visited.add(source);
|
|
632
1324
|
const target = isArray(source) ? [] : {};
|
|
633
1325
|
forEach(source, (value, key) => {
|
|
634
|
-
const reducedValue = visit(value
|
|
1326
|
+
const reducedValue = visit(value);
|
|
635
1327
|
!isUndefined(reducedValue) && (target[key] = reducedValue);
|
|
636
1328
|
});
|
|
637
|
-
|
|
1329
|
+
visited.delete(source);
|
|
638
1330
|
return target;
|
|
639
1331
|
}
|
|
640
1332
|
}
|
|
641
1333
|
return source;
|
|
642
1334
|
};
|
|
643
|
-
return visit(obj
|
|
1335
|
+
return visit(obj);
|
|
644
1336
|
};
|
|
645
1337
|
const isAsyncFn = kindOfTest("AsyncFunction");
|
|
646
1338
|
const isThenable = (thing) => thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
|
|
@@ -649,22 +1341,24 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
|
|
649
1341
|
return setImmediate;
|
|
650
1342
|
}
|
|
651
1343
|
return postMessageSupported ? ((token, callbacks) => {
|
|
652
|
-
_global.addEventListener(
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
1344
|
+
_global.addEventListener(
|
|
1345
|
+
"message",
|
|
1346
|
+
({ source, data }) => {
|
|
1347
|
+
if (source === _global && data === token) {
|
|
1348
|
+
callbacks.length && callbacks.shift()();
|
|
1349
|
+
}
|
|
1350
|
+
},
|
|
1351
|
+
false
|
|
1352
|
+
);
|
|
657
1353
|
return (cb) => {
|
|
658
1354
|
callbacks.push(cb);
|
|
659
1355
|
_global.postMessage(token, "*");
|
|
660
1356
|
};
|
|
661
1357
|
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
|
662
|
-
})(
|
|
663
|
-
typeof setImmediate === "function",
|
|
664
|
-
isFunction$1(_global.postMessage)
|
|
665
|
-
);
|
|
1358
|
+
})(typeof setImmediate === "function", isFunction$1(_global.postMessage));
|
|
666
1359
|
const asap = typeof queueMicrotask !== "undefined" ? queueMicrotask.bind(_global) : typeof process !== "undefined" && process.nextTick || _setImmediate;
|
|
667
1360
|
const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
|
|
1361
|
+
const isSafeIterable = (thing) => thing != null && hasOwnInPrototypeChain(thing, iterator) && isIterable(thing);
|
|
668
1362
|
const utils$1 = {
|
|
669
1363
|
isArray,
|
|
670
1364
|
isArrayBuffer,
|
|
@@ -684,6 +1378,8 @@ const utils$1 = {
|
|
|
684
1378
|
isUndefined,
|
|
685
1379
|
isDate,
|
|
686
1380
|
isFile,
|
|
1381
|
+
isReactNativeBlob,
|
|
1382
|
+
isReactNative,
|
|
687
1383
|
isBlob,
|
|
688
1384
|
isRegExp,
|
|
689
1385
|
isFunction: isFunction$1,
|
|
@@ -708,6 +1404,8 @@ const utils$1 = {
|
|
|
708
1404
|
hasOwnProperty,
|
|
709
1405
|
hasOwnProp: hasOwnProperty,
|
|
710
1406
|
// an alias to avoid ESLint no-prototype-builtins detection
|
|
1407
|
+
hasOwnInPrototypeChain,
|
|
1408
|
+
getSafeProp,
|
|
711
1409
|
reduceDescriptors,
|
|
712
1410
|
freezeMethods,
|
|
713
1411
|
toObjectSet,
|
|
@@ -723,85 +1421,470 @@ const utils$1 = {
|
|
|
723
1421
|
isThenable,
|
|
724
1422
|
setImmediate: _setImmediate,
|
|
725
1423
|
asap,
|
|
726
|
-
isIterable
|
|
1424
|
+
isIterable,
|
|
1425
|
+
isSafeIterable
|
|
727
1426
|
};
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
1427
|
+
const ignoreDuplicateOf = utils$1.toObjectSet([
|
|
1428
|
+
"age",
|
|
1429
|
+
"authorization",
|
|
1430
|
+
"content-length",
|
|
1431
|
+
"content-type",
|
|
1432
|
+
"etag",
|
|
1433
|
+
"expires",
|
|
1434
|
+
"from",
|
|
1435
|
+
"host",
|
|
1436
|
+
"if-modified-since",
|
|
1437
|
+
"if-unmodified-since",
|
|
1438
|
+
"last-modified",
|
|
1439
|
+
"location",
|
|
1440
|
+
"max-forwards",
|
|
1441
|
+
"proxy-authorization",
|
|
1442
|
+
"referer",
|
|
1443
|
+
"retry-after",
|
|
1444
|
+
"user-agent"
|
|
1445
|
+
]);
|
|
1446
|
+
const parseHeaders = (rawHeaders) => {
|
|
1447
|
+
const parsed = {};
|
|
1448
|
+
let key;
|
|
1449
|
+
let val;
|
|
1450
|
+
let i;
|
|
1451
|
+
rawHeaders && rawHeaders.split("\n").forEach(function parser(line) {
|
|
1452
|
+
i = line.indexOf(":");
|
|
1453
|
+
key = line.substring(0, i).trim().toLowerCase();
|
|
1454
|
+
val = line.substring(i + 1).trim();
|
|
1455
|
+
if (!key || parsed[key] && ignoreDuplicateOf[key]) {
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1458
|
+
if (key === "set-cookie") {
|
|
1459
|
+
if (parsed[key]) {
|
|
1460
|
+
parsed[key].push(val);
|
|
1461
|
+
} else {
|
|
1462
|
+
parsed[key] = [val];
|
|
1463
|
+
}
|
|
1464
|
+
} else {
|
|
1465
|
+
parsed[key] = parsed[key] ? parsed[key] + ", " + val : val;
|
|
1466
|
+
}
|
|
1467
|
+
});
|
|
1468
|
+
return parsed;
|
|
1469
|
+
};
|
|
1470
|
+
function trimSPorHTAB(str2) {
|
|
1471
|
+
let start = 0;
|
|
1472
|
+
let end = str2.length;
|
|
1473
|
+
while (start < end) {
|
|
1474
|
+
const code = str2.charCodeAt(start);
|
|
1475
|
+
if (code !== 9 && code !== 32) {
|
|
1476
|
+
break;
|
|
1477
|
+
}
|
|
1478
|
+
start += 1;
|
|
1479
|
+
}
|
|
1480
|
+
while (end > start) {
|
|
1481
|
+
const code = str2.charCodeAt(end - 1);
|
|
1482
|
+
if (code !== 9 && code !== 32) {
|
|
1483
|
+
break;
|
|
1484
|
+
}
|
|
1485
|
+
end -= 1;
|
|
1486
|
+
}
|
|
1487
|
+
return start === 0 && end === str2.length ? str2 : str2.slice(start, end);
|
|
1488
|
+
}
|
|
1489
|
+
const INVALID_UNICODE_HEADER_VALUE_CHARS = new RegExp("[\\u0000-\\u0008\\u000a-\\u001f\\u007f]+", "g");
|
|
1490
|
+
const INVALID_BYTE_STRING_HEADER_VALUE_CHARS = new RegExp("[^\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+", "g");
|
|
1491
|
+
function sanitizeValue(value, invalidChars) {
|
|
1492
|
+
if (utils$1.isArray(value)) {
|
|
1493
|
+
return value.map((item) => sanitizeValue(item, invalidChars));
|
|
1494
|
+
}
|
|
1495
|
+
return trimSPorHTAB(String(value).replace(invalidChars, ""));
|
|
1496
|
+
}
|
|
1497
|
+
const sanitizeHeaderValue = (value) => sanitizeValue(value, INVALID_UNICODE_HEADER_VALUE_CHARS);
|
|
1498
|
+
const sanitizeByteStringHeaderValue = (value) => sanitizeValue(value, INVALID_BYTE_STRING_HEADER_VALUE_CHARS);
|
|
1499
|
+
function toByteStringHeaderObject(headers) {
|
|
1500
|
+
const byteStringHeaders = /* @__PURE__ */ Object.create(null);
|
|
1501
|
+
utils$1.forEach(headers.toJSON(), (value, header) => {
|
|
1502
|
+
byteStringHeaders[header] = sanitizeByteStringHeaderValue(value);
|
|
1503
|
+
});
|
|
1504
|
+
return byteStringHeaders;
|
|
1505
|
+
}
|
|
1506
|
+
const $internals = Symbol("internals");
|
|
1507
|
+
function normalizeHeader(header) {
|
|
1508
|
+
return header && String(header).trim().toLowerCase();
|
|
1509
|
+
}
|
|
1510
|
+
function normalizeValue(value) {
|
|
1511
|
+
if (value === false || value == null) {
|
|
1512
|
+
return value;
|
|
1513
|
+
}
|
|
1514
|
+
return utils$1.isArray(value) ? value.map(normalizeValue) : sanitizeHeaderValue(String(value));
|
|
1515
|
+
}
|
|
1516
|
+
function parseTokens(str2) {
|
|
1517
|
+
const tokens = /* @__PURE__ */ Object.create(null);
|
|
1518
|
+
const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
|
|
1519
|
+
let match;
|
|
1520
|
+
while (match = tokensRE.exec(str2)) {
|
|
1521
|
+
tokens[match[1]] = match[2];
|
|
1522
|
+
}
|
|
1523
|
+
return tokens;
|
|
1524
|
+
}
|
|
1525
|
+
const isValidHeaderName = (str2) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str2.trim());
|
|
1526
|
+
function matchHeaderValue(context, value, header, filter2, isHeaderNameFilter) {
|
|
1527
|
+
if (utils$1.isFunction(filter2)) {
|
|
1528
|
+
return filter2.call(this, value, header);
|
|
1529
|
+
}
|
|
1530
|
+
if (isHeaderNameFilter) {
|
|
1531
|
+
value = header;
|
|
1532
|
+
}
|
|
1533
|
+
if (!utils$1.isString(value)) return;
|
|
1534
|
+
if (utils$1.isString(filter2)) {
|
|
1535
|
+
return value.indexOf(filter2) !== -1;
|
|
1536
|
+
}
|
|
1537
|
+
if (utils$1.isRegExp(filter2)) {
|
|
1538
|
+
return filter2.test(value);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
function formatHeader(header) {
|
|
1542
|
+
return header.trim().toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str2) => {
|
|
1543
|
+
return char.toUpperCase() + str2;
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
function buildAccessors(obj, header) {
|
|
1547
|
+
const accessorName = utils$1.toCamelCase(" " + header);
|
|
1548
|
+
["get", "set", "has"].forEach((methodName) => {
|
|
1549
|
+
Object.defineProperty(obj, methodName + accessorName, {
|
|
1550
|
+
// Null-proto descriptor so a polluted Object.prototype.get cannot turn
|
|
1551
|
+
// this data descriptor into an accessor descriptor on the way in.
|
|
1552
|
+
__proto__: null,
|
|
1553
|
+
value: function(arg1, arg2, arg3) {
|
|
1554
|
+
return this[methodName].call(this, header, arg1, arg2, arg3);
|
|
1555
|
+
},
|
|
1556
|
+
configurable: true
|
|
1557
|
+
});
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
let AxiosHeaders$1 = class AxiosHeaders {
|
|
1561
|
+
constructor(headers) {
|
|
1562
|
+
headers && this.set(headers);
|
|
1563
|
+
}
|
|
1564
|
+
set(header, valueOrRewrite, rewrite) {
|
|
1565
|
+
const self2 = this;
|
|
1566
|
+
function setHeader(_value, _header, _rewrite) {
|
|
1567
|
+
const lHeader = normalizeHeader(_header);
|
|
1568
|
+
if (!lHeader) {
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
const key = utils$1.findKey(self2, lHeader);
|
|
1572
|
+
if (!key || self2[key] === void 0 || _rewrite === true || _rewrite === void 0 && self2[key] !== false) {
|
|
1573
|
+
self2[key || _header] = normalizeValue(_value);
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
const setHeaders = (headers, _rewrite) => utils$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
|
|
1577
|
+
if (utils$1.isPlainObject(header) || header instanceof this.constructor) {
|
|
1578
|
+
setHeaders(header, valueOrRewrite);
|
|
1579
|
+
} else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
|
1580
|
+
setHeaders(parseHeaders(header), valueOrRewrite);
|
|
1581
|
+
} else if (utils$1.isObject(header) && utils$1.isSafeIterable(header)) {
|
|
1582
|
+
let obj = /* @__PURE__ */ Object.create(null), dest, key;
|
|
1583
|
+
for (const entry of header) {
|
|
1584
|
+
if (!utils$1.isArray(entry)) {
|
|
1585
|
+
throw new TypeError("Object iterator must return a key-value pair");
|
|
1586
|
+
}
|
|
1587
|
+
key = entry[0];
|
|
1588
|
+
if (utils$1.hasOwnProp(obj, key)) {
|
|
1589
|
+
dest = obj[key];
|
|
1590
|
+
obj[key] = utils$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]];
|
|
1591
|
+
} else {
|
|
1592
|
+
obj[key] = entry[1];
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
setHeaders(obj, valueOrRewrite);
|
|
1596
|
+
} else {
|
|
1597
|
+
header != null && setHeader(valueOrRewrite, header, rewrite);
|
|
1598
|
+
}
|
|
1599
|
+
return this;
|
|
1600
|
+
}
|
|
1601
|
+
get(header, parser) {
|
|
1602
|
+
header = normalizeHeader(header);
|
|
1603
|
+
if (header) {
|
|
1604
|
+
const key = utils$1.findKey(this, header);
|
|
1605
|
+
if (key) {
|
|
1606
|
+
const value = this[key];
|
|
1607
|
+
if (!parser) {
|
|
1608
|
+
return value;
|
|
1609
|
+
}
|
|
1610
|
+
if (parser === true) {
|
|
1611
|
+
return parseTokens(value);
|
|
1612
|
+
}
|
|
1613
|
+
if (utils$1.isFunction(parser)) {
|
|
1614
|
+
return parser.call(this, value, key);
|
|
1615
|
+
}
|
|
1616
|
+
if (utils$1.isRegExp(parser)) {
|
|
1617
|
+
return parser.exec(value);
|
|
1618
|
+
}
|
|
1619
|
+
throw new TypeError("parser must be boolean|regexp|function");
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
has(header, matcher) {
|
|
1624
|
+
header = normalizeHeader(header);
|
|
1625
|
+
if (header) {
|
|
1626
|
+
const key = utils$1.findKey(this, header);
|
|
1627
|
+
return !!(key && this[key] !== void 0 && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
|
|
1628
|
+
}
|
|
1629
|
+
return false;
|
|
1630
|
+
}
|
|
1631
|
+
delete(header, matcher) {
|
|
1632
|
+
const self2 = this;
|
|
1633
|
+
let deleted = false;
|
|
1634
|
+
function deleteHeader(_header) {
|
|
1635
|
+
_header = normalizeHeader(_header);
|
|
1636
|
+
if (_header) {
|
|
1637
|
+
const key = utils$1.findKey(self2, _header);
|
|
1638
|
+
if (key && (!matcher || matchHeaderValue(self2, self2[key], key, matcher))) {
|
|
1639
|
+
delete self2[key];
|
|
1640
|
+
deleted = true;
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
if (utils$1.isArray(header)) {
|
|
1645
|
+
header.forEach(deleteHeader);
|
|
1646
|
+
} else {
|
|
1647
|
+
deleteHeader(header);
|
|
1648
|
+
}
|
|
1649
|
+
return deleted;
|
|
1650
|
+
}
|
|
1651
|
+
clear(matcher) {
|
|
1652
|
+
const keys = Object.keys(this);
|
|
1653
|
+
let i = keys.length;
|
|
1654
|
+
let deleted = false;
|
|
1655
|
+
while (i--) {
|
|
1656
|
+
const key = keys[i];
|
|
1657
|
+
if (!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
|
|
1658
|
+
delete this[key];
|
|
1659
|
+
deleted = true;
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
return deleted;
|
|
1663
|
+
}
|
|
1664
|
+
normalize(format) {
|
|
1665
|
+
const self2 = this;
|
|
1666
|
+
const headers = {};
|
|
1667
|
+
utils$1.forEach(this, (value, header) => {
|
|
1668
|
+
const key = utils$1.findKey(headers, header);
|
|
1669
|
+
if (key) {
|
|
1670
|
+
self2[key] = normalizeValue(value);
|
|
1671
|
+
delete self2[header];
|
|
1672
|
+
return;
|
|
1673
|
+
}
|
|
1674
|
+
const normalized = format ? formatHeader(header) : String(header).trim();
|
|
1675
|
+
if (normalized !== header) {
|
|
1676
|
+
delete self2[header];
|
|
1677
|
+
}
|
|
1678
|
+
self2[normalized] = normalizeValue(value);
|
|
1679
|
+
headers[normalized] = true;
|
|
1680
|
+
});
|
|
1681
|
+
return this;
|
|
1682
|
+
}
|
|
1683
|
+
concat(...targets) {
|
|
1684
|
+
return this.constructor.concat(this, ...targets);
|
|
1685
|
+
}
|
|
1686
|
+
toJSON(asStrings) {
|
|
1687
|
+
const obj = /* @__PURE__ */ Object.create(null);
|
|
1688
|
+
utils$1.forEach(this, (value, header) => {
|
|
1689
|
+
value != null && value !== false && (obj[header] = asStrings && utils$1.isArray(value) ? value.join(", ") : value);
|
|
1690
|
+
});
|
|
1691
|
+
return obj;
|
|
1692
|
+
}
|
|
1693
|
+
[Symbol.iterator]() {
|
|
1694
|
+
return Object.entries(this.toJSON())[Symbol.iterator]();
|
|
1695
|
+
}
|
|
1696
|
+
toString() {
|
|
1697
|
+
return Object.entries(this.toJSON()).map(([header, value]) => header + ": " + value).join("\n");
|
|
1698
|
+
}
|
|
1699
|
+
getSetCookie() {
|
|
1700
|
+
return this.get("set-cookie") || [];
|
|
1701
|
+
}
|
|
1702
|
+
get [Symbol.toStringTag]() {
|
|
1703
|
+
return "AxiosHeaders";
|
|
1704
|
+
}
|
|
1705
|
+
static from(thing) {
|
|
1706
|
+
return thing instanceof this ? thing : new this(thing);
|
|
1707
|
+
}
|
|
1708
|
+
static concat(first, ...targets) {
|
|
1709
|
+
const computed = new this(first);
|
|
1710
|
+
targets.forEach((target) => computed.set(target));
|
|
1711
|
+
return computed;
|
|
1712
|
+
}
|
|
1713
|
+
static accessor(header) {
|
|
1714
|
+
const internals = this[$internals] = this[$internals] = {
|
|
1715
|
+
accessors: {}
|
|
1716
|
+
};
|
|
1717
|
+
const accessors = internals.accessors;
|
|
1718
|
+
const prototype2 = this.prototype;
|
|
1719
|
+
function defineAccessor(_header) {
|
|
1720
|
+
const lHeader = normalizeHeader(_header);
|
|
1721
|
+
if (!accessors[lHeader]) {
|
|
1722
|
+
buildAccessors(prototype2, _header);
|
|
1723
|
+
accessors[lHeader] = true;
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
utils$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
|
1727
|
+
return this;
|
|
1728
|
+
}
|
|
803
1729
|
};
|
|
1730
|
+
AxiosHeaders$1.accessor([
|
|
1731
|
+
"Content-Type",
|
|
1732
|
+
"Content-Length",
|
|
1733
|
+
"Accept",
|
|
1734
|
+
"Accept-Encoding",
|
|
1735
|
+
"User-Agent",
|
|
1736
|
+
"Authorization"
|
|
1737
|
+
]);
|
|
1738
|
+
utils$1.reduceDescriptors(AxiosHeaders$1.prototype, ({ value }, key) => {
|
|
1739
|
+
let mapped = key[0].toUpperCase() + key.slice(1);
|
|
1740
|
+
return {
|
|
1741
|
+
get: () => value,
|
|
1742
|
+
set(headerValue) {
|
|
1743
|
+
this[mapped] = headerValue;
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
});
|
|
1747
|
+
utils$1.freezeMethods(AxiosHeaders$1);
|
|
1748
|
+
const REDACTED = "[REDACTED ****]";
|
|
1749
|
+
function hasOwnOrPrototypeToJSON(source) {
|
|
1750
|
+
if (utils$1.hasOwnProp(source, "toJSON")) {
|
|
1751
|
+
return true;
|
|
1752
|
+
}
|
|
1753
|
+
let prototype2 = Object.getPrototypeOf(source);
|
|
1754
|
+
while (prototype2 && prototype2 !== Object.prototype) {
|
|
1755
|
+
if (utils$1.hasOwnProp(prototype2, "toJSON")) {
|
|
1756
|
+
return true;
|
|
1757
|
+
}
|
|
1758
|
+
prototype2 = Object.getPrototypeOf(prototype2);
|
|
1759
|
+
}
|
|
1760
|
+
return false;
|
|
1761
|
+
}
|
|
1762
|
+
function redactConfig(config2, redactKeys) {
|
|
1763
|
+
const lowerKeys = new Set(redactKeys.map((k) => String(k).toLowerCase()));
|
|
1764
|
+
const seen = [];
|
|
1765
|
+
const visit = (source) => {
|
|
1766
|
+
if (source === null || typeof source !== "object") return source;
|
|
1767
|
+
if (utils$1.isBuffer(source)) return source;
|
|
1768
|
+
if (seen.indexOf(source) !== -1) return void 0;
|
|
1769
|
+
if (source instanceof AxiosHeaders$1) {
|
|
1770
|
+
source = source.toJSON();
|
|
1771
|
+
}
|
|
1772
|
+
seen.push(source);
|
|
1773
|
+
let result;
|
|
1774
|
+
if (utils$1.isArray(source)) {
|
|
1775
|
+
result = [];
|
|
1776
|
+
source.forEach((v, i) => {
|
|
1777
|
+
const reducedValue = visit(v);
|
|
1778
|
+
if (!utils$1.isUndefined(reducedValue)) {
|
|
1779
|
+
result[i] = reducedValue;
|
|
1780
|
+
}
|
|
1781
|
+
});
|
|
1782
|
+
} else {
|
|
1783
|
+
if (!utils$1.isPlainObject(source) && hasOwnOrPrototypeToJSON(source)) {
|
|
1784
|
+
seen.pop();
|
|
1785
|
+
return source;
|
|
1786
|
+
}
|
|
1787
|
+
result = /* @__PURE__ */ Object.create(null);
|
|
1788
|
+
for (const [key, value] of Object.entries(source)) {
|
|
1789
|
+
const reducedValue = lowerKeys.has(key.toLowerCase()) ? REDACTED : visit(value);
|
|
1790
|
+
if (!utils$1.isUndefined(reducedValue)) {
|
|
1791
|
+
result[key] = reducedValue;
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
seen.pop();
|
|
1796
|
+
return result;
|
|
1797
|
+
};
|
|
1798
|
+
return visit(config2);
|
|
1799
|
+
}
|
|
1800
|
+
let AxiosError$1 = class AxiosError extends Error {
|
|
1801
|
+
static from(error, code, config2, request, response, customProps) {
|
|
1802
|
+
const axiosError = new AxiosError(error.message, code || error.code, config2, request, response);
|
|
1803
|
+
Object.defineProperty(axiosError, "cause", {
|
|
1804
|
+
__proto__: null,
|
|
1805
|
+
value: error,
|
|
1806
|
+
writable: true,
|
|
1807
|
+
enumerable: false,
|
|
1808
|
+
configurable: true
|
|
1809
|
+
});
|
|
1810
|
+
axiosError.name = error.name;
|
|
1811
|
+
if (error.status != null && axiosError.status == null) {
|
|
1812
|
+
axiosError.status = error.status;
|
|
1813
|
+
}
|
|
1814
|
+
customProps && Object.assign(axiosError, customProps);
|
|
1815
|
+
return axiosError;
|
|
1816
|
+
}
|
|
1817
|
+
/**
|
|
1818
|
+
* Create an Error with the specified message, config, error code, request and response.
|
|
1819
|
+
*
|
|
1820
|
+
* @param {string} message The error message.
|
|
1821
|
+
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
|
1822
|
+
* @param {Object} [config] The config.
|
|
1823
|
+
* @param {Object} [request] The request.
|
|
1824
|
+
* @param {Object} [response] The response.
|
|
1825
|
+
*
|
|
1826
|
+
* @returns {Error} The created error.
|
|
1827
|
+
*/
|
|
1828
|
+
constructor(message, code, config2, request, response) {
|
|
1829
|
+
super(message);
|
|
1830
|
+
Object.defineProperty(this, "message", {
|
|
1831
|
+
// Null-proto descriptor so a polluted Object.prototype.get cannot turn
|
|
1832
|
+
// this data descriptor into an accessor descriptor on the way in.
|
|
1833
|
+
__proto__: null,
|
|
1834
|
+
value: message,
|
|
1835
|
+
enumerable: true,
|
|
1836
|
+
writable: true,
|
|
1837
|
+
configurable: true
|
|
1838
|
+
});
|
|
1839
|
+
this.name = "AxiosError";
|
|
1840
|
+
this.isAxiosError = true;
|
|
1841
|
+
code && (this.code = code);
|
|
1842
|
+
config2 && (this.config = config2);
|
|
1843
|
+
request && (this.request = request);
|
|
1844
|
+
if (response) {
|
|
1845
|
+
this.response = response;
|
|
1846
|
+
this.status = response.status;
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
toJSON() {
|
|
1850
|
+
const config2 = this.config;
|
|
1851
|
+
const redactKeys = config2 && utils$1.hasOwnProp(config2, "redact") ? config2.redact : void 0;
|
|
1852
|
+
const serializedConfig = utils$1.isArray(redactKeys) && redactKeys.length > 0 ? redactConfig(config2, redactKeys) : utils$1.toJSONObject(config2);
|
|
1853
|
+
return {
|
|
1854
|
+
// Standard
|
|
1855
|
+
message: this.message,
|
|
1856
|
+
name: this.name,
|
|
1857
|
+
// Microsoft
|
|
1858
|
+
description: this.description,
|
|
1859
|
+
number: this.number,
|
|
1860
|
+
// Mozilla
|
|
1861
|
+
fileName: this.fileName,
|
|
1862
|
+
lineNumber: this.lineNumber,
|
|
1863
|
+
columnNumber: this.columnNumber,
|
|
1864
|
+
stack: this.stack,
|
|
1865
|
+
// Axios
|
|
1866
|
+
config: serializedConfig,
|
|
1867
|
+
code: this.code,
|
|
1868
|
+
status: this.status
|
|
1869
|
+
};
|
|
1870
|
+
}
|
|
1871
|
+
};
|
|
1872
|
+
AxiosError$1.ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
|
|
1873
|
+
AxiosError$1.ERR_BAD_OPTION = "ERR_BAD_OPTION";
|
|
1874
|
+
AxiosError$1.ECONNABORTED = "ECONNABORTED";
|
|
1875
|
+
AxiosError$1.ETIMEDOUT = "ETIMEDOUT";
|
|
1876
|
+
AxiosError$1.ECONNREFUSED = "ECONNREFUSED";
|
|
1877
|
+
AxiosError$1.ERR_NETWORK = "ERR_NETWORK";
|
|
1878
|
+
AxiosError$1.ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
|
|
1879
|
+
AxiosError$1.ERR_DEPRECATED = "ERR_DEPRECATED";
|
|
1880
|
+
AxiosError$1.ERR_BAD_RESPONSE = "ERR_BAD_RESPONSE";
|
|
1881
|
+
AxiosError$1.ERR_BAD_REQUEST = "ERR_BAD_REQUEST";
|
|
1882
|
+
AxiosError$1.ERR_CANCELED = "ERR_CANCELED";
|
|
1883
|
+
AxiosError$1.ERR_NOT_SUPPORT = "ERR_NOT_SUPPORT";
|
|
1884
|
+
AxiosError$1.ERR_INVALID_URL = "ERR_INVALID_URL";
|
|
1885
|
+
AxiosError$1.ERR_FORM_DATA_DEPTH_EXCEEDED = "ERR_FORM_DATA_DEPTH_EXCEEDED";
|
|
804
1886
|
const httpAdapter = null;
|
|
1887
|
+
const DEFAULT_FORM_DATA_MAX_DEPTH = 100;
|
|
805
1888
|
function isVisitable(thing) {
|
|
806
1889
|
return utils$1.isPlainObject(thing) || utils$1.isArray(thing);
|
|
807
1890
|
}
|
|
@@ -826,19 +1909,26 @@ function toFormData$1(obj, formData, options) {
|
|
|
826
1909
|
throw new TypeError("target must be an object");
|
|
827
1910
|
}
|
|
828
1911
|
formData = formData || new FormData();
|
|
829
|
-
options = utils$1.toFlatObject(
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
1912
|
+
options = utils$1.toFlatObject(
|
|
1913
|
+
options,
|
|
1914
|
+
{
|
|
1915
|
+
metaTokens: true,
|
|
1916
|
+
dots: false,
|
|
1917
|
+
indexes: false
|
|
1918
|
+
},
|
|
1919
|
+
false,
|
|
1920
|
+
function defined(option, source) {
|
|
1921
|
+
return !utils$1.isUndefined(source[option]);
|
|
1922
|
+
}
|
|
1923
|
+
);
|
|
836
1924
|
const metaTokens = options.metaTokens;
|
|
837
1925
|
const visitor = options.visitor || defaultVisitor;
|
|
838
1926
|
const dots = options.dots;
|
|
839
1927
|
const indexes = options.indexes;
|
|
840
1928
|
const _Blob = options.Blob || typeof Blob !== "undefined" && Blob;
|
|
1929
|
+
const maxDepth = options.maxDepth === void 0 ? DEFAULT_FORM_DATA_MAX_DEPTH : options.maxDepth;
|
|
841
1930
|
const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
|
|
1931
|
+
const stack = [];
|
|
842
1932
|
if (!utils$1.isFunction(visitor)) {
|
|
843
1933
|
throw new TypeError("visitor must be a function");
|
|
844
1934
|
}
|
|
@@ -854,16 +1944,51 @@ function toFormData$1(obj, formData, options) {
|
|
|
854
1944
|
throw new AxiosError$1("Blob is not supported. Use a Buffer instead.");
|
|
855
1945
|
}
|
|
856
1946
|
if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
|
|
857
|
-
|
|
1947
|
+
if (useBlob && typeof _Blob === "function") {
|
|
1948
|
+
return new _Blob([value]);
|
|
1949
|
+
}
|
|
1950
|
+
if (typeof Buffer !== "undefined") {
|
|
1951
|
+
return Buffer.from(value);
|
|
1952
|
+
}
|
|
1953
|
+
throw new AxiosError$1("Blob is not supported. Use a Buffer instead.", AxiosError$1.ERR_NOT_SUPPORT);
|
|
858
1954
|
}
|
|
859
1955
|
return value;
|
|
860
1956
|
}
|
|
1957
|
+
function throwIfMaxDepthExceeded(depth) {
|
|
1958
|
+
if (depth > maxDepth) {
|
|
1959
|
+
throw new AxiosError$1(
|
|
1960
|
+
"Object is too deeply nested (" + depth + " levels). Max depth: " + maxDepth,
|
|
1961
|
+
AxiosError$1.ERR_FORM_DATA_DEPTH_EXCEEDED
|
|
1962
|
+
);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
function stringifyWithDepthLimit(value, depth) {
|
|
1966
|
+
if (maxDepth === Infinity) {
|
|
1967
|
+
return JSON.stringify(value);
|
|
1968
|
+
}
|
|
1969
|
+
const ancestors = [];
|
|
1970
|
+
return JSON.stringify(value, function limitDepth(_key, currentValue) {
|
|
1971
|
+
if (!utils$1.isObject(currentValue)) {
|
|
1972
|
+
return currentValue;
|
|
1973
|
+
}
|
|
1974
|
+
while (ancestors.length && ancestors[ancestors.length - 1] !== this) {
|
|
1975
|
+
ancestors.pop();
|
|
1976
|
+
}
|
|
1977
|
+
ancestors.push(currentValue);
|
|
1978
|
+
throwIfMaxDepthExceeded(depth + ancestors.length - 1);
|
|
1979
|
+
return currentValue;
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
861
1982
|
function defaultVisitor(value, key, path) {
|
|
862
1983
|
let arr = value;
|
|
1984
|
+
if (utils$1.isReactNative(formData) && utils$1.isReactNativeBlob(value)) {
|
|
1985
|
+
formData.append(renderKey(path, key, dots), convertValue(value));
|
|
1986
|
+
return false;
|
|
1987
|
+
}
|
|
863
1988
|
if (value && !path && typeof value === "object") {
|
|
864
1989
|
if (utils$1.endsWith(key, "{}")) {
|
|
865
1990
|
key = metaTokens ? key : key.slice(0, -2);
|
|
866
|
-
value =
|
|
1991
|
+
value = stringifyWithDepthLimit(value, 1);
|
|
867
1992
|
} else if (utils$1.isArray(value) && isFlatArray(value) || (utils$1.isFileList(value) || utils$1.endsWith(key, "[]")) && (arr = utils$1.toArray(value))) {
|
|
868
1993
|
key = removeBrackets(key);
|
|
869
1994
|
arr.forEach(function each(el, index2) {
|
|
@@ -882,28 +2007,22 @@ function toFormData$1(obj, formData, options) {
|
|
|
882
2007
|
formData.append(renderKey(path, key, dots), convertValue(value));
|
|
883
2008
|
return false;
|
|
884
2009
|
}
|
|
885
|
-
const stack = [];
|
|
886
2010
|
const exposedHelpers = Object.assign(predicates, {
|
|
887
2011
|
defaultVisitor,
|
|
888
2012
|
convertValue,
|
|
889
2013
|
isVisitable
|
|
890
2014
|
});
|
|
891
|
-
function build(value, path) {
|
|
2015
|
+
function build(value, path, depth = 0) {
|
|
892
2016
|
if (utils$1.isUndefined(value)) return;
|
|
2017
|
+
throwIfMaxDepthExceeded(depth);
|
|
893
2018
|
if (stack.indexOf(value) !== -1) {
|
|
894
|
-
throw Error("Circular reference detected in " + path.join("."));
|
|
2019
|
+
throw new Error("Circular reference detected in " + path.join("."));
|
|
895
2020
|
}
|
|
896
2021
|
stack.push(value);
|
|
897
2022
|
utils$1.forEach(value, function each(el, key) {
|
|
898
|
-
const result = !(utils$1.isUndefined(el) || el === null) && visitor.call(
|
|
899
|
-
formData,
|
|
900
|
-
el,
|
|
901
|
-
utils$1.isString(key) ? key.trim() : key,
|
|
902
|
-
path,
|
|
903
|
-
exposedHelpers
|
|
904
|
-
);
|
|
2023
|
+
const result = !(utils$1.isUndefined(el) || el === null) && visitor.call(formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers);
|
|
905
2024
|
if (result === true) {
|
|
906
|
-
build(el, path ? path.concat(key) : [key]);
|
|
2025
|
+
build(el, path ? path.concat(key) : [key], depth + 1);
|
|
907
2026
|
}
|
|
908
2027
|
});
|
|
909
2028
|
stack.pop();
|
|
@@ -914,17 +2033,16 @@ function toFormData$1(obj, formData, options) {
|
|
|
914
2033
|
build(obj);
|
|
915
2034
|
return formData;
|
|
916
2035
|
}
|
|
917
|
-
function encode$1(
|
|
2036
|
+
function encode$1(str2) {
|
|
918
2037
|
const charMap = {
|
|
919
2038
|
"!": "%21",
|
|
920
2039
|
"'": "%27",
|
|
921
2040
|
"(": "%28",
|
|
922
2041
|
")": "%29",
|
|
923
2042
|
"~": "%7E",
|
|
924
|
-
"%20": "+"
|
|
925
|
-
"%00": "\0"
|
|
2043
|
+
"%20": "+"
|
|
926
2044
|
};
|
|
927
|
-
return encodeURIComponent(
|
|
2045
|
+
return encodeURIComponent(str2).replace(/[!'()~]|%20/g, function replacer(match) {
|
|
928
2046
|
return charMap[match];
|
|
929
2047
|
});
|
|
930
2048
|
}
|
|
@@ -933,13 +2051,11 @@ function AxiosURLSearchParams(params, options) {
|
|
|
933
2051
|
params && toFormData$1(params, this, options);
|
|
934
2052
|
}
|
|
935
2053
|
const prototype = AxiosURLSearchParams.prototype;
|
|
936
|
-
prototype.append = function append(
|
|
937
|
-
this._pairs.push([
|
|
2054
|
+
prototype.append = function append(name2, value) {
|
|
2055
|
+
this._pairs.push([name2, value]);
|
|
938
2056
|
};
|
|
939
2057
|
prototype.toString = function toString2(encoder) {
|
|
940
|
-
const _encode = encoder ?
|
|
941
|
-
return encoder.call(this, value, encode$1);
|
|
942
|
-
} : encode$1;
|
|
2058
|
+
const _encode = encoder ? (value) => encoder.call(this, value, encode$1) : encode$1;
|
|
943
2059
|
return this._pairs.map(function each(pair) {
|
|
944
2060
|
return _encode(pair[0]) + "=" + _encode(pair[1]);
|
|
945
2061
|
}, "").join("&");
|
|
@@ -951,18 +2067,17 @@ function buildURL(url, params, options) {
|
|
|
951
2067
|
if (!params) {
|
|
952
2068
|
return url;
|
|
953
2069
|
}
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
options
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
const serializeFn = options && options.serialize;
|
|
2070
|
+
url = url || "";
|
|
2071
|
+
const _options = utils$1.isFunction(options) ? {
|
|
2072
|
+
serialize: options
|
|
2073
|
+
} : options;
|
|
2074
|
+
const _encode = utils$1.getSafeProp(_options, "encode") || encode;
|
|
2075
|
+
const serializeFn = utils$1.getSafeProp(_options, "serialize");
|
|
961
2076
|
let serializedParams;
|
|
962
2077
|
if (serializeFn) {
|
|
963
|
-
serializedParams = serializeFn(params,
|
|
2078
|
+
serializedParams = serializeFn(params, _options);
|
|
964
2079
|
} else {
|
|
965
|
-
serializedParams = utils$1.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params,
|
|
2080
|
+
serializedParams = utils$1.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params, _options).toString(_encode);
|
|
966
2081
|
}
|
|
967
2082
|
if (serializedParams) {
|
|
968
2083
|
const hashmarkIndex = url.indexOf("#");
|
|
@@ -982,6 +2097,7 @@ class InterceptorManager {
|
|
|
982
2097
|
*
|
|
983
2098
|
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
|
984
2099
|
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
|
2100
|
+
* @param {Object} options The options for the interceptor, synchronous and runWhen
|
|
985
2101
|
*
|
|
986
2102
|
* @return {Number} An ID used to remove interceptor later
|
|
987
2103
|
*/
|
|
@@ -999,7 +2115,7 @@ class InterceptorManager {
|
|
|
999
2115
|
*
|
|
1000
2116
|
* @param {Number} id The ID that was returned by `use`
|
|
1001
2117
|
*
|
|
1002
|
-
* @returns {
|
|
2118
|
+
* @returns {void}
|
|
1003
2119
|
*/
|
|
1004
2120
|
eject(id) {
|
|
1005
2121
|
if (this.handlers[id]) {
|
|
@@ -1037,7 +2153,10 @@ class InterceptorManager {
|
|
|
1037
2153
|
const transitionalDefaults = {
|
|
1038
2154
|
silentJSONParsing: true,
|
|
1039
2155
|
forcedJSONParsing: true,
|
|
1040
|
-
clarifyTimeoutError: false
|
|
2156
|
+
clarifyTimeoutError: false,
|
|
2157
|
+
legacyInterceptorReqResOrdering: true,
|
|
2158
|
+
advertiseZstdAcceptEncoding: false,
|
|
2159
|
+
validateStatusUndefinedResolves: true
|
|
1041
2160
|
};
|
|
1042
2161
|
const URLSearchParams$1 = typeof URLSearchParams !== "undefined" ? URLSearchParams : AxiosURLSearchParams;
|
|
1043
2162
|
const FormData$1 = typeof FormData !== "undefined" ? FormData : null;
|
|
@@ -1058,456 +2177,210 @@ const hasStandardBrowserWebWorkerEnv = (() => {
|
|
|
1058
2177
|
return typeof WorkerGlobalScope !== "undefined" && // eslint-disable-next-line no-undef
|
|
1059
2178
|
self instanceof WorkerGlobalScope && typeof self.importScripts === "function";
|
|
1060
2179
|
})();
|
|
1061
|
-
const origin = hasBrowserEnv && window.location.href || "http://localhost";
|
|
1062
|
-
const utils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1063
|
-
__proto__: null,
|
|
1064
|
-
hasBrowserEnv,
|
|
1065
|
-
hasStandardBrowserEnv,
|
|
1066
|
-
hasStandardBrowserWebWorkerEnv,
|
|
1067
|
-
navigator: _navigator,
|
|
1068
|
-
origin
|
|
1069
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
1070
|
-
const platform = {
|
|
1071
|
-
...utils,
|
|
1072
|
-
...platform$1
|
|
1073
|
-
};
|
|
1074
|
-
function toURLEncodedForm(data, options) {
|
|
1075
|
-
return toFormData$1(data, new platform.classes.URLSearchParams(), {
|
|
1076
|
-
visitor: function(value, key, path, helpers) {
|
|
1077
|
-
if (platform.isNode && utils$1.isBuffer(value)) {
|
|
1078
|
-
this.append(key, value.toString("base64"));
|
|
1079
|
-
return false;
|
|
1080
|
-
}
|
|
1081
|
-
return helpers.defaultVisitor.apply(this, arguments);
|
|
1082
|
-
},
|
|
1083
|
-
...options
|
|
1084
|
-
});
|
|
1085
|
-
}
|
|
1086
|
-
function parsePropPath(name) {
|
|
1087
|
-
return utils$1.matchAll(/\w+|\[(\w*)]/g, name).map((match) => {
|
|
1088
|
-
return match[0] === "[]" ? "" : match[1] || match[0];
|
|
1089
|
-
});
|
|
1090
|
-
}
|
|
1091
|
-
function arrayToObject(arr) {
|
|
1092
|
-
const obj = {};
|
|
1093
|
-
const keys = Object.keys(arr);
|
|
1094
|
-
let i;
|
|
1095
|
-
const len = keys.length;
|
|
1096
|
-
let key;
|
|
1097
|
-
for (i = 0; i < len; i++) {
|
|
1098
|
-
key = keys[i];
|
|
1099
|
-
obj[key] = arr[key];
|
|
1100
|
-
}
|
|
1101
|
-
return obj;
|
|
1102
|
-
}
|
|
1103
|
-
function formDataToJSON(formData) {
|
|
1104
|
-
function buildPath(path, value, target, index2) {
|
|
1105
|
-
let name = path[index2++];
|
|
1106
|
-
if (name === "__proto__") return true;
|
|
1107
|
-
const isNumericKey = Number.isFinite(+name);
|
|
1108
|
-
const isLast = index2 >= path.length;
|
|
1109
|
-
name = !name && utils$1.isArray(target) ? target.length : name;
|
|
1110
|
-
if (isLast) {
|
|
1111
|
-
if (utils$1.hasOwnProp(target, name)) {
|
|
1112
|
-
target[name] = [target[name], value];
|
|
1113
|
-
} else {
|
|
1114
|
-
target[name] = value;
|
|
1115
|
-
}
|
|
1116
|
-
return !isNumericKey;
|
|
1117
|
-
}
|
|
1118
|
-
if (!target[name] || !utils$1.isObject(target[name])) {
|
|
1119
|
-
target[name] = [];
|
|
1120
|
-
}
|
|
1121
|
-
const result = buildPath(path, value, target[name], index2);
|
|
1122
|
-
if (result && utils$1.isArray(target[name])) {
|
|
1123
|
-
target[name] = arrayToObject(target[name]);
|
|
1124
|
-
}
|
|
1125
|
-
return !isNumericKey;
|
|
1126
|
-
}
|
|
1127
|
-
if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
|
|
1128
|
-
const obj = {};
|
|
1129
|
-
utils$1.forEachEntry(formData, (name, value) => {
|
|
1130
|
-
buildPath(parsePropPath(name), value, obj, 0);
|
|
1131
|
-
});
|
|
1132
|
-
return obj;
|
|
1133
|
-
}
|
|
1134
|
-
return null;
|
|
1135
|
-
}
|
|
1136
|
-
function stringifySafely(rawValue, parser, encoder) {
|
|
1137
|
-
if (utils$1.isString(rawValue)) {
|
|
1138
|
-
try {
|
|
1139
|
-
(parser || JSON.parse)(rawValue);
|
|
1140
|
-
return utils$1.trim(rawValue);
|
|
1141
|
-
} catch (e) {
|
|
1142
|
-
if (e.name !== "SyntaxError") {
|
|
1143
|
-
throw e;
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
return (encoder || JSON.stringify)(rawValue);
|
|
1148
|
-
}
|
|
1149
|
-
const defaults = {
|
|
1150
|
-
transitional: transitionalDefaults,
|
|
1151
|
-
adapter: ["xhr", "http", "fetch"],
|
|
1152
|
-
transformRequest: [function transformRequest(data, headers) {
|
|
1153
|
-
const contentType = headers.getContentType() || "";
|
|
1154
|
-
const hasJSONContentType = contentType.indexOf("application/json") > -1;
|
|
1155
|
-
const isObjectPayload = utils$1.isObject(data);
|
|
1156
|
-
if (isObjectPayload && utils$1.isHTMLForm(data)) {
|
|
1157
|
-
data = new FormData(data);
|
|
1158
|
-
}
|
|
1159
|
-
const isFormData2 = utils$1.isFormData(data);
|
|
1160
|
-
if (isFormData2) {
|
|
1161
|
-
return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
|
|
1162
|
-
}
|
|
1163
|
-
if (utils$1.isArrayBuffer(data) || utils$1.isBuffer(data) || utils$1.isStream(data) || utils$1.isFile(data) || utils$1.isBlob(data) || utils$1.isReadableStream(data)) {
|
|
1164
|
-
return data;
|
|
1165
|
-
}
|
|
1166
|
-
if (utils$1.isArrayBufferView(data)) {
|
|
1167
|
-
return data.buffer;
|
|
1168
|
-
}
|
|
1169
|
-
if (utils$1.isURLSearchParams(data)) {
|
|
1170
|
-
headers.setContentType("application/x-www-form-urlencoded;charset=utf-8", false);
|
|
1171
|
-
return data.toString();
|
|
1172
|
-
}
|
|
1173
|
-
let isFileList2;
|
|
1174
|
-
if (isObjectPayload) {
|
|
1175
|
-
if (contentType.indexOf("application/x-www-form-urlencoded") > -1) {
|
|
1176
|
-
return toURLEncodedForm(data, this.formSerializer).toString();
|
|
1177
|
-
}
|
|
1178
|
-
if ((isFileList2 = utils$1.isFileList(data)) || contentType.indexOf("multipart/form-data") > -1) {
|
|
1179
|
-
const _FormData = this.env && this.env.FormData;
|
|
1180
|
-
return toFormData$1(
|
|
1181
|
-
isFileList2 ? { "files[]": data } : data,
|
|
1182
|
-
_FormData && new _FormData(),
|
|
1183
|
-
this.formSerializer
|
|
1184
|
-
);
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
if (isObjectPayload || hasJSONContentType) {
|
|
1188
|
-
headers.setContentType("application/json", false);
|
|
1189
|
-
return stringifySafely(data);
|
|
1190
|
-
}
|
|
1191
|
-
return data;
|
|
1192
|
-
}],
|
|
1193
|
-
transformResponse: [function transformResponse(data) {
|
|
1194
|
-
const transitional2 = this.transitional || defaults.transitional;
|
|
1195
|
-
const forcedJSONParsing = transitional2 && transitional2.forcedJSONParsing;
|
|
1196
|
-
const JSONRequested = this.responseType === "json";
|
|
1197
|
-
if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
|
|
1198
|
-
return data;
|
|
1199
|
-
}
|
|
1200
|
-
if (data && utils$1.isString(data) && (forcedJSONParsing && !this.responseType || JSONRequested)) {
|
|
1201
|
-
const silentJSONParsing = transitional2 && transitional2.silentJSONParsing;
|
|
1202
|
-
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
|
1203
|
-
try {
|
|
1204
|
-
return JSON.parse(data, this.parseReviver);
|
|
1205
|
-
} catch (e) {
|
|
1206
|
-
if (strictJSONParsing) {
|
|
1207
|
-
if (e.name === "SyntaxError") {
|
|
1208
|
-
throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_RESPONSE, this, null, this.response);
|
|
1209
|
-
}
|
|
1210
|
-
throw e;
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
return data;
|
|
1215
|
-
}],
|
|
1216
|
-
/**
|
|
1217
|
-
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
|
1218
|
-
* timeout is not created.
|
|
1219
|
-
*/
|
|
1220
|
-
timeout: 0,
|
|
1221
|
-
xsrfCookieName: "XSRF-TOKEN",
|
|
1222
|
-
xsrfHeaderName: "X-XSRF-TOKEN",
|
|
1223
|
-
maxContentLength: -1,
|
|
1224
|
-
maxBodyLength: -1,
|
|
1225
|
-
env: {
|
|
1226
|
-
FormData: platform.classes.FormData,
|
|
1227
|
-
Blob: platform.classes.Blob
|
|
1228
|
-
},
|
|
1229
|
-
validateStatus: function validateStatus(status) {
|
|
1230
|
-
return status >= 200 && status < 300;
|
|
1231
|
-
},
|
|
1232
|
-
headers: {
|
|
1233
|
-
common: {
|
|
1234
|
-
"Accept": "application/json, text/plain, */*",
|
|
1235
|
-
"Content-Type": void 0
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
};
|
|
1239
|
-
utils$1.forEach(["delete", "get", "head", "post", "put", "patch"], (method) => {
|
|
1240
|
-
defaults.headers[method] = {};
|
|
1241
|
-
});
|
|
1242
|
-
const ignoreDuplicateOf = utils$1.toObjectSet([
|
|
1243
|
-
"age",
|
|
1244
|
-
"authorization",
|
|
1245
|
-
"content-length",
|
|
1246
|
-
"content-type",
|
|
1247
|
-
"etag",
|
|
1248
|
-
"expires",
|
|
1249
|
-
"from",
|
|
1250
|
-
"host",
|
|
1251
|
-
"if-modified-since",
|
|
1252
|
-
"if-unmodified-since",
|
|
1253
|
-
"last-modified",
|
|
1254
|
-
"location",
|
|
1255
|
-
"max-forwards",
|
|
1256
|
-
"proxy-authorization",
|
|
1257
|
-
"referer",
|
|
1258
|
-
"retry-after",
|
|
1259
|
-
"user-agent"
|
|
1260
|
-
]);
|
|
1261
|
-
const parseHeaders = (rawHeaders) => {
|
|
1262
|
-
const parsed = {};
|
|
1263
|
-
let key;
|
|
1264
|
-
let val;
|
|
1265
|
-
let i;
|
|
1266
|
-
rawHeaders && rawHeaders.split("\n").forEach(function parser(line) {
|
|
1267
|
-
i = line.indexOf(":");
|
|
1268
|
-
key = line.substring(0, i).trim().toLowerCase();
|
|
1269
|
-
val = line.substring(i + 1).trim();
|
|
1270
|
-
if (!key || parsed[key] && ignoreDuplicateOf[key]) {
|
|
1271
|
-
return;
|
|
1272
|
-
}
|
|
1273
|
-
if (key === "set-cookie") {
|
|
1274
|
-
if (parsed[key]) {
|
|
1275
|
-
parsed[key].push(val);
|
|
1276
|
-
} else {
|
|
1277
|
-
parsed[key] = [val];
|
|
1278
|
-
}
|
|
1279
|
-
} else {
|
|
1280
|
-
parsed[key] = parsed[key] ? parsed[key] + ", " + val : val;
|
|
1281
|
-
}
|
|
1282
|
-
});
|
|
1283
|
-
return parsed;
|
|
1284
|
-
};
|
|
1285
|
-
const $internals = Symbol("internals");
|
|
1286
|
-
function normalizeHeader(header) {
|
|
1287
|
-
return header && String(header).trim().toLowerCase();
|
|
1288
|
-
}
|
|
1289
|
-
function normalizeValue(value) {
|
|
1290
|
-
if (value === false || value == null) {
|
|
1291
|
-
return value;
|
|
1292
|
-
}
|
|
1293
|
-
return utils$1.isArray(value) ? value.map(normalizeValue) : String(value);
|
|
1294
|
-
}
|
|
1295
|
-
function parseTokens(str) {
|
|
1296
|
-
const tokens = /* @__PURE__ */ Object.create(null);
|
|
1297
|
-
const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
|
|
1298
|
-
let match;
|
|
1299
|
-
while (match = tokensRE.exec(str)) {
|
|
1300
|
-
tokens[match[1]] = match[2];
|
|
1301
|
-
}
|
|
1302
|
-
return tokens;
|
|
1303
|
-
}
|
|
1304
|
-
const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
|
|
1305
|
-
function matchHeaderValue(context, value, header, filter2, isHeaderNameFilter) {
|
|
1306
|
-
if (utils$1.isFunction(filter2)) {
|
|
1307
|
-
return filter2.call(this, value, header);
|
|
1308
|
-
}
|
|
1309
|
-
if (isHeaderNameFilter) {
|
|
1310
|
-
value = header;
|
|
1311
|
-
}
|
|
1312
|
-
if (!utils$1.isString(value)) return;
|
|
1313
|
-
if (utils$1.isString(filter2)) {
|
|
1314
|
-
return value.indexOf(filter2) !== -1;
|
|
1315
|
-
}
|
|
1316
|
-
if (utils$1.isRegExp(filter2)) {
|
|
1317
|
-
return filter2.test(value);
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
function formatHeader(header) {
|
|
1321
|
-
return header.trim().toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
|
|
1322
|
-
return char.toUpperCase() + str;
|
|
1323
|
-
});
|
|
1324
|
-
}
|
|
1325
|
-
function buildAccessors(obj, header) {
|
|
1326
|
-
const accessorName = utils$1.toCamelCase(" " + header);
|
|
1327
|
-
["get", "set", "has"].forEach((methodName) => {
|
|
1328
|
-
Object.defineProperty(obj, methodName + accessorName, {
|
|
1329
|
-
value: function(arg1, arg2, arg3) {
|
|
1330
|
-
return this[methodName].call(this, header, arg1, arg2, arg3);
|
|
1331
|
-
},
|
|
1332
|
-
configurable: true
|
|
1333
|
-
});
|
|
1334
|
-
});
|
|
1335
|
-
}
|
|
1336
|
-
let AxiosHeaders$1 = class AxiosHeaders {
|
|
1337
|
-
constructor(headers) {
|
|
1338
|
-
headers && this.set(headers);
|
|
1339
|
-
}
|
|
1340
|
-
set(header, valueOrRewrite, rewrite) {
|
|
1341
|
-
const self2 = this;
|
|
1342
|
-
function setHeader(_value, _header, _rewrite) {
|
|
1343
|
-
const lHeader = normalizeHeader(_header);
|
|
1344
|
-
if (!lHeader) {
|
|
1345
|
-
throw new Error("header name must be a non-empty string");
|
|
1346
|
-
}
|
|
1347
|
-
const key = utils$1.findKey(self2, lHeader);
|
|
1348
|
-
if (!key || self2[key] === void 0 || _rewrite === true || _rewrite === void 0 && self2[key] !== false) {
|
|
1349
|
-
self2[key || _header] = normalizeValue(_value);
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
const setHeaders = (headers, _rewrite) => utils$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
|
|
1353
|
-
if (utils$1.isPlainObject(header) || header instanceof this.constructor) {
|
|
1354
|
-
setHeaders(header, valueOrRewrite);
|
|
1355
|
-
} else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
|
1356
|
-
setHeaders(parseHeaders(header), valueOrRewrite);
|
|
1357
|
-
} else if (utils$1.isObject(header) && utils$1.isIterable(header)) {
|
|
1358
|
-
let obj = {}, dest, key;
|
|
1359
|
-
for (const entry of header) {
|
|
1360
|
-
if (!utils$1.isArray(entry)) {
|
|
1361
|
-
throw TypeError("Object iterator must return a key-value pair");
|
|
1362
|
-
}
|
|
1363
|
-
obj[key = entry[0]] = (dest = obj[key]) ? utils$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]] : entry[1];
|
|
1364
|
-
}
|
|
1365
|
-
setHeaders(obj, valueOrRewrite);
|
|
1366
|
-
} else {
|
|
1367
|
-
header != null && setHeader(valueOrRewrite, header, rewrite);
|
|
1368
|
-
}
|
|
1369
|
-
return this;
|
|
1370
|
-
}
|
|
1371
|
-
get(header, parser) {
|
|
1372
|
-
header = normalizeHeader(header);
|
|
1373
|
-
if (header) {
|
|
1374
|
-
const key = utils$1.findKey(this, header);
|
|
1375
|
-
if (key) {
|
|
1376
|
-
const value = this[key];
|
|
1377
|
-
if (!parser) {
|
|
1378
|
-
return value;
|
|
1379
|
-
}
|
|
1380
|
-
if (parser === true) {
|
|
1381
|
-
return parseTokens(value);
|
|
1382
|
-
}
|
|
1383
|
-
if (utils$1.isFunction(parser)) {
|
|
1384
|
-
return parser.call(this, value, key);
|
|
1385
|
-
}
|
|
1386
|
-
if (utils$1.isRegExp(parser)) {
|
|
1387
|
-
return parser.exec(value);
|
|
1388
|
-
}
|
|
1389
|
-
throw new TypeError("parser must be boolean|regexp|function");
|
|
2180
|
+
const origin = hasBrowserEnv && window.location.href || "http://localhost";
|
|
2181
|
+
const utils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2182
|
+
__proto__: null,
|
|
2183
|
+
hasBrowserEnv,
|
|
2184
|
+
hasStandardBrowserEnv,
|
|
2185
|
+
hasStandardBrowserWebWorkerEnv,
|
|
2186
|
+
navigator: _navigator,
|
|
2187
|
+
origin
|
|
2188
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
2189
|
+
const platform = {
|
|
2190
|
+
...utils,
|
|
2191
|
+
...platform$1
|
|
2192
|
+
};
|
|
2193
|
+
function toURLEncodedForm(data, options) {
|
|
2194
|
+
return toFormData$1(data, new platform.classes.URLSearchParams(), {
|
|
2195
|
+
visitor: function(value, key, path, helpers) {
|
|
2196
|
+
if (platform.isNode && utils$1.isBuffer(value)) {
|
|
2197
|
+
this.append(key, value.toString("base64"));
|
|
2198
|
+
return false;
|
|
1390
2199
|
}
|
|
1391
|
-
|
|
2200
|
+
return helpers.defaultVisitor.apply(this, arguments);
|
|
2201
|
+
},
|
|
2202
|
+
...options
|
|
2203
|
+
});
|
|
2204
|
+
}
|
|
2205
|
+
const MAX_DEPTH = DEFAULT_FORM_DATA_MAX_DEPTH;
|
|
2206
|
+
function throwIfDepthExceeded(index2) {
|
|
2207
|
+
if (index2 > MAX_DEPTH) {
|
|
2208
|
+
throw new AxiosError$1(
|
|
2209
|
+
"FormData field is too deeply nested (" + index2 + " levels). Max depth: " + MAX_DEPTH,
|
|
2210
|
+
AxiosError$1.ERR_FORM_DATA_DEPTH_EXCEEDED
|
|
2211
|
+
);
|
|
1392
2212
|
}
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
2213
|
+
}
|
|
2214
|
+
function parsePropPath(name2) {
|
|
2215
|
+
const path = [];
|
|
2216
|
+
const pattern = /\w+|\[(\w*)]/g;
|
|
2217
|
+
let match;
|
|
2218
|
+
while ((match = pattern.exec(name2)) !== null) {
|
|
2219
|
+
throwIfDepthExceeded(path.length);
|
|
2220
|
+
path.push(match[0] === "[]" ? "" : match[1] || match[0]);
|
|
1400
2221
|
}
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
2222
|
+
return path;
|
|
2223
|
+
}
|
|
2224
|
+
function arrayToObject(arr) {
|
|
2225
|
+
const obj = {};
|
|
2226
|
+
const keys = Object.keys(arr);
|
|
2227
|
+
let i;
|
|
2228
|
+
const len = keys.length;
|
|
2229
|
+
let key;
|
|
2230
|
+
for (i = 0; i < len; i++) {
|
|
2231
|
+
key = keys[i];
|
|
2232
|
+
obj[key] = arr[key];
|
|
2233
|
+
}
|
|
2234
|
+
return obj;
|
|
2235
|
+
}
|
|
2236
|
+
function formDataToJSON(formData) {
|
|
2237
|
+
function buildPath(path, value, target, index2) {
|
|
2238
|
+
throwIfDepthExceeded(index2);
|
|
2239
|
+
let name2 = path[index2++];
|
|
2240
|
+
if (name2 === "__proto__") return true;
|
|
2241
|
+
const isNumericKey = Number.isFinite(+name2);
|
|
2242
|
+
const isLast = index2 >= path.length;
|
|
2243
|
+
name2 = !name2 && utils$1.isArray(target) ? target.length : name2;
|
|
2244
|
+
if (isLast) {
|
|
2245
|
+
if (utils$1.hasOwnProp(target, name2)) {
|
|
2246
|
+
target[name2] = utils$1.isArray(target[name2]) ? target[name2].concat(value) : [target[name2], value];
|
|
2247
|
+
} else {
|
|
2248
|
+
target[name2] = value;
|
|
1412
2249
|
}
|
|
2250
|
+
return !isNumericKey;
|
|
1413
2251
|
}
|
|
1414
|
-
if (utils$1.
|
|
1415
|
-
|
|
1416
|
-
} else {
|
|
1417
|
-
deleteHeader(header);
|
|
2252
|
+
if (!utils$1.hasOwnProp(target, name2) || !utils$1.isObject(target[name2])) {
|
|
2253
|
+
target[name2] = [];
|
|
1418
2254
|
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
const keys = Object.keys(this);
|
|
1423
|
-
let i = keys.length;
|
|
1424
|
-
let deleted = false;
|
|
1425
|
-
while (i--) {
|
|
1426
|
-
const key = keys[i];
|
|
1427
|
-
if (!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
|
|
1428
|
-
delete this[key];
|
|
1429
|
-
deleted = true;
|
|
1430
|
-
}
|
|
2255
|
+
const result = buildPath(path, value, target[name2], index2);
|
|
2256
|
+
if (result && utils$1.isArray(target[name2])) {
|
|
2257
|
+
target[name2] = arrayToObject(target[name2]);
|
|
1431
2258
|
}
|
|
1432
|
-
return
|
|
1433
|
-
}
|
|
1434
|
-
normalize(format) {
|
|
1435
|
-
const self2 = this;
|
|
1436
|
-
const headers = {};
|
|
1437
|
-
utils$1.forEach(this, (value, header) => {
|
|
1438
|
-
const key = utils$1.findKey(headers, header);
|
|
1439
|
-
if (key) {
|
|
1440
|
-
self2[key] = normalizeValue(value);
|
|
1441
|
-
delete self2[header];
|
|
1442
|
-
return;
|
|
1443
|
-
}
|
|
1444
|
-
const normalized = format ? formatHeader(header) : String(header).trim();
|
|
1445
|
-
if (normalized !== header) {
|
|
1446
|
-
delete self2[header];
|
|
1447
|
-
}
|
|
1448
|
-
self2[normalized] = normalizeValue(value);
|
|
1449
|
-
headers[normalized] = true;
|
|
1450
|
-
});
|
|
1451
|
-
return this;
|
|
1452
|
-
}
|
|
1453
|
-
concat(...targets) {
|
|
1454
|
-
return this.constructor.concat(this, ...targets);
|
|
2259
|
+
return !isNumericKey;
|
|
1455
2260
|
}
|
|
1456
|
-
|
|
1457
|
-
const obj =
|
|
1458
|
-
utils$1.
|
|
1459
|
-
|
|
2261
|
+
if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
|
|
2262
|
+
const obj = {};
|
|
2263
|
+
utils$1.forEachEntry(formData, (name2, value) => {
|
|
2264
|
+
buildPath(parsePropPath(name2), value, obj, 0);
|
|
1460
2265
|
});
|
|
1461
2266
|
return obj;
|
|
1462
2267
|
}
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
return thing instanceof this ? thing : new this(thing);
|
|
1477
|
-
}
|
|
1478
|
-
static concat(first, ...targets) {
|
|
1479
|
-
const computed = new this(first);
|
|
1480
|
-
targets.forEach((target) => computed.set(target));
|
|
1481
|
-
return computed;
|
|
2268
|
+
return null;
|
|
2269
|
+
}
|
|
2270
|
+
const own = (obj, key) => obj != null && utils$1.hasOwnProp(obj, key) ? obj[key] : void 0;
|
|
2271
|
+
function stringifySafely(rawValue, parser, encoder) {
|
|
2272
|
+
if (utils$1.isString(rawValue)) {
|
|
2273
|
+
try {
|
|
2274
|
+
(parser || JSON.parse)(rawValue);
|
|
2275
|
+
return utils$1.trim(rawValue);
|
|
2276
|
+
} catch (e) {
|
|
2277
|
+
if (e.name !== "SyntaxError") {
|
|
2278
|
+
throw e;
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
1482
2281
|
}
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
function
|
|
1490
|
-
const
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
2282
|
+
return (encoder || JSON.stringify)(rawValue);
|
|
2283
|
+
}
|
|
2284
|
+
const defaults = {
|
|
2285
|
+
transitional: transitionalDefaults,
|
|
2286
|
+
adapter: ["xhr", "http", "fetch"],
|
|
2287
|
+
transformRequest: [
|
|
2288
|
+
function transformRequest(data, headers) {
|
|
2289
|
+
const contentType = headers.getContentType() || "";
|
|
2290
|
+
const hasJSONContentType = contentType.indexOf("application/json") > -1;
|
|
2291
|
+
const isObjectPayload = utils$1.isObject(data);
|
|
2292
|
+
if (isObjectPayload && utils$1.isHTMLForm(data)) {
|
|
2293
|
+
data = new FormData(data);
|
|
2294
|
+
}
|
|
2295
|
+
const isFormData2 = utils$1.isFormData(data);
|
|
2296
|
+
if (isFormData2) {
|
|
2297
|
+
return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
|
|
2298
|
+
}
|
|
2299
|
+
if (utils$1.isArrayBuffer(data) || utils$1.isBuffer(data) || utils$1.isStream(data) || utils$1.isFile(data) || utils$1.isBlob(data) || utils$1.isReadableStream(data)) {
|
|
2300
|
+
return data;
|
|
1494
2301
|
}
|
|
2302
|
+
if (utils$1.isArrayBufferView(data)) {
|
|
2303
|
+
return data.buffer;
|
|
2304
|
+
}
|
|
2305
|
+
if (utils$1.isURLSearchParams(data)) {
|
|
2306
|
+
headers.setContentType("application/x-www-form-urlencoded;charset=utf-8", false);
|
|
2307
|
+
return data.toString();
|
|
2308
|
+
}
|
|
2309
|
+
let isFileList2;
|
|
2310
|
+
if (isObjectPayload) {
|
|
2311
|
+
const formSerializer = own(this, "formSerializer");
|
|
2312
|
+
if (contentType.indexOf("application/x-www-form-urlencoded") > -1) {
|
|
2313
|
+
return toURLEncodedForm(data, formSerializer).toString();
|
|
2314
|
+
}
|
|
2315
|
+
if ((isFileList2 = utils$1.isFileList(data)) || contentType.indexOf("multipart/form-data") > -1) {
|
|
2316
|
+
const env = own(this, "env");
|
|
2317
|
+
const _FormData = env && env.FormData;
|
|
2318
|
+
return toFormData$1(
|
|
2319
|
+
isFileList2 ? { "files[]": data } : data,
|
|
2320
|
+
_FormData && new _FormData(),
|
|
2321
|
+
formSerializer
|
|
2322
|
+
);
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
if (isObjectPayload || hasJSONContentType) {
|
|
2326
|
+
headers.setContentType("application/json", false);
|
|
2327
|
+
return stringifySafely(data);
|
|
2328
|
+
}
|
|
2329
|
+
return data;
|
|
2330
|
+
}
|
|
2331
|
+
],
|
|
2332
|
+
transformResponse: [
|
|
2333
|
+
function transformResponse(data) {
|
|
2334
|
+
const transitional2 = own(this, "transitional") || defaults.transitional;
|
|
2335
|
+
const forcedJSONParsing = transitional2 && transitional2.forcedJSONParsing;
|
|
2336
|
+
const responseType = own(this, "responseType");
|
|
2337
|
+
const JSONRequested = responseType === "json";
|
|
2338
|
+
if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
|
|
2339
|
+
return data;
|
|
2340
|
+
}
|
|
2341
|
+
if (data && utils$1.isString(data) && (forcedJSONParsing && !responseType || JSONRequested)) {
|
|
2342
|
+
const silentJSONParsing = transitional2 && transitional2.silentJSONParsing;
|
|
2343
|
+
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
|
2344
|
+
try {
|
|
2345
|
+
return JSON.parse(data, own(this, "parseReviver"));
|
|
2346
|
+
} catch (e) {
|
|
2347
|
+
if (strictJSONParsing) {
|
|
2348
|
+
if (e.name === "SyntaxError") {
|
|
2349
|
+
throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_RESPONSE, this, null, own(this, "response"));
|
|
2350
|
+
}
|
|
2351
|
+
throw e;
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
return data;
|
|
2356
|
+
}
|
|
2357
|
+
],
|
|
2358
|
+
/**
|
|
2359
|
+
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
|
2360
|
+
* timeout is not created.
|
|
2361
|
+
*/
|
|
2362
|
+
timeout: 0,
|
|
2363
|
+
xsrfCookieName: "XSRF-TOKEN",
|
|
2364
|
+
xsrfHeaderName: "X-XSRF-TOKEN",
|
|
2365
|
+
maxContentLength: -1,
|
|
2366
|
+
maxBodyLength: -1,
|
|
2367
|
+
env: {
|
|
2368
|
+
FormData: platform.classes.FormData,
|
|
2369
|
+
Blob: platform.classes.Blob
|
|
2370
|
+
},
|
|
2371
|
+
validateStatus: function validateStatus(status) {
|
|
2372
|
+
return status >= 200 && status < 300;
|
|
2373
|
+
},
|
|
2374
|
+
headers: {
|
|
2375
|
+
common: {
|
|
2376
|
+
Accept: "application/json, text/plain, */*",
|
|
2377
|
+
"Content-Type": void 0
|
|
1495
2378
|
}
|
|
1496
|
-
utils$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
|
1497
|
-
return this;
|
|
1498
2379
|
}
|
|
1499
2380
|
};
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
let mapped = key[0].toUpperCase() + key.slice(1);
|
|
1503
|
-
return {
|
|
1504
|
-
get: () => value,
|
|
1505
|
-
set(headerValue) {
|
|
1506
|
-
this[mapped] = headerValue;
|
|
1507
|
-
}
|
|
1508
|
-
};
|
|
2381
|
+
utils$1.forEach(["delete", "get", "head", "post", "put", "patch", "query"], (method) => {
|
|
2382
|
+
defaults.headers[method] = {};
|
|
1509
2383
|
});
|
|
1510
|
-
utils$1.freezeMethods(AxiosHeaders$1);
|
|
1511
2384
|
function transformData(fns, response) {
|
|
1512
2385
|
const config2 = this || defaults;
|
|
1513
2386
|
const context = response || config2;
|
|
@@ -1522,13 +2395,22 @@ function transformData(fns, response) {
|
|
|
1522
2395
|
function isCancel$1(value) {
|
|
1523
2396
|
return !!(value && value.__CANCEL__);
|
|
1524
2397
|
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
}
|
|
2398
|
+
let CanceledError$1 = class CanceledError extends AxiosError$1 {
|
|
2399
|
+
/**
|
|
2400
|
+
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
|
2401
|
+
*
|
|
2402
|
+
* @param {string=} message The message.
|
|
2403
|
+
* @param {Object=} config The config.
|
|
2404
|
+
* @param {Object=} request The request.
|
|
2405
|
+
*
|
|
2406
|
+
* @returns {CanceledError} The created error.
|
|
2407
|
+
*/
|
|
2408
|
+
constructor(message, config2, request) {
|
|
2409
|
+
super(message == null ? "canceled" : message, AxiosError$1.ERR_CANCELED, config2, request);
|
|
2410
|
+
this.name = "CanceledError";
|
|
2411
|
+
this.__CANCEL__ = true;
|
|
2412
|
+
}
|
|
2413
|
+
};
|
|
1532
2414
|
function settle(resolve, reject, response) {
|
|
1533
2415
|
const validateStatus2 = response.config.validateStatus;
|
|
1534
2416
|
if (!response.status || !validateStatus2 || validateStatus2(response.status)) {
|
|
@@ -1536,7 +2418,7 @@ function settle(resolve, reject, response) {
|
|
|
1536
2418
|
} else {
|
|
1537
2419
|
reject(new AxiosError$1(
|
|
1538
2420
|
"Request failed with status code " + response.status,
|
|
1539
|
-
|
|
2421
|
+
response.status >= 400 && response.status < 500 ? AxiosError$1.ERR_BAD_REQUEST : AxiosError$1.ERR_BAD_RESPONSE,
|
|
1540
2422
|
response.config,
|
|
1541
2423
|
response.request,
|
|
1542
2424
|
response
|
|
@@ -1544,7 +2426,7 @@ function settle(resolve, reject, response) {
|
|
|
1544
2426
|
}
|
|
1545
2427
|
}
|
|
1546
2428
|
function parseProtocol(url) {
|
|
1547
|
-
const match = /^([-+\w]{1,25})(
|
|
2429
|
+
const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url);
|
|
1548
2430
|
return match && match[1] || "";
|
|
1549
2431
|
}
|
|
1550
2432
|
function speedometer(samplesCount, min) {
|
|
@@ -1616,19 +2498,22 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
|
|
1616
2498
|
let bytesNotified = 0;
|
|
1617
2499
|
const _speedometer = speedometer(50, 250);
|
|
1618
2500
|
return throttle((e) => {
|
|
1619
|
-
|
|
2501
|
+
if (!e || typeof e.loaded !== "number") {
|
|
2502
|
+
return;
|
|
2503
|
+
}
|
|
2504
|
+
const rawLoaded = e.loaded;
|
|
1620
2505
|
const total = e.lengthComputable ? e.total : void 0;
|
|
1621
|
-
const
|
|
2506
|
+
const loaded = total != null ? Math.min(rawLoaded, total) : rawLoaded;
|
|
2507
|
+
const progressBytes = Math.max(0, loaded - bytesNotified);
|
|
1622
2508
|
const rate = _speedometer(progressBytes);
|
|
1623
|
-
|
|
1624
|
-
bytesNotified = loaded;
|
|
2509
|
+
bytesNotified = Math.max(bytesNotified, loaded);
|
|
1625
2510
|
const data = {
|
|
1626
2511
|
loaded,
|
|
1627
2512
|
total,
|
|
1628
2513
|
progress: total ? loaded / total : void 0,
|
|
1629
2514
|
bytes: progressBytes,
|
|
1630
2515
|
rate: rate ? rate : void 0,
|
|
1631
|
-
estimated: rate && total
|
|
2516
|
+
estimated: rate && total ? (total - loaded) / rate : void 0,
|
|
1632
2517
|
event: e,
|
|
1633
2518
|
lengthComputable: total != null,
|
|
1634
2519
|
[isDownloadStream ? "download" : "upload"]: true
|
|
@@ -1638,11 +2523,14 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
|
|
1638
2523
|
};
|
|
1639
2524
|
const progressEventDecorator = (total, throttled) => {
|
|
1640
2525
|
const lengthComputable = total != null;
|
|
1641
|
-
return [
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
2526
|
+
return [
|
|
2527
|
+
(loaded) => throttled[0]({
|
|
2528
|
+
lengthComputable,
|
|
2529
|
+
total,
|
|
2530
|
+
loaded
|
|
2531
|
+
}),
|
|
2532
|
+
throttled[1]
|
|
2533
|
+
];
|
|
1646
2534
|
};
|
|
1647
2535
|
const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
|
|
1648
2536
|
const isURLSameOrigin = platform.hasStandardBrowserEnv ? /* @__PURE__ */ ((origin2, isMSIE) => (url) => {
|
|
@@ -1655,20 +2543,44 @@ const isURLSameOrigin = platform.hasStandardBrowserEnv ? /* @__PURE__ */ ((origi
|
|
|
1655
2543
|
const cookies = platform.hasStandardBrowserEnv ? (
|
|
1656
2544
|
// Standard browser envs support document.cookie
|
|
1657
2545
|
{
|
|
1658
|
-
write(
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
utils$1.
|
|
1662
|
-
|
|
1663
|
-
|
|
2546
|
+
write(name2, value, expires, path, domain, secure, sameSite) {
|
|
2547
|
+
if (typeof document === "undefined") return;
|
|
2548
|
+
const cookie = [`${name2}=${encodeURIComponent(value)}`];
|
|
2549
|
+
if (utils$1.isNumber(expires)) {
|
|
2550
|
+
cookie.push(`expires=${new Date(expires).toUTCString()}`);
|
|
2551
|
+
}
|
|
2552
|
+
if (utils$1.isString(path)) {
|
|
2553
|
+
cookie.push(`path=${path}`);
|
|
2554
|
+
}
|
|
2555
|
+
if (utils$1.isString(domain)) {
|
|
2556
|
+
cookie.push(`domain=${domain}`);
|
|
2557
|
+
}
|
|
2558
|
+
if (secure === true) {
|
|
2559
|
+
cookie.push("secure");
|
|
2560
|
+
}
|
|
2561
|
+
if (utils$1.isString(sameSite)) {
|
|
2562
|
+
cookie.push(`SameSite=${sameSite}`);
|
|
2563
|
+
}
|
|
1664
2564
|
document.cookie = cookie.join("; ");
|
|
1665
2565
|
},
|
|
1666
|
-
read(
|
|
1667
|
-
|
|
1668
|
-
|
|
2566
|
+
read(name2) {
|
|
2567
|
+
if (typeof document === "undefined") return null;
|
|
2568
|
+
const cookies2 = document.cookie.split(";");
|
|
2569
|
+
for (let i = 0; i < cookies2.length; i++) {
|
|
2570
|
+
const cookie = cookies2[i].replace(/^\s+/, "");
|
|
2571
|
+
const eq = cookie.indexOf("=");
|
|
2572
|
+
if (eq !== -1 && cookie.slice(0, eq) === name2) {
|
|
2573
|
+
try {
|
|
2574
|
+
return decodeURIComponent(cookie.slice(eq + 1));
|
|
2575
|
+
} catch (e) {
|
|
2576
|
+
return cookie.slice(eq + 1);
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
return null;
|
|
1669
2581
|
},
|
|
1670
|
-
remove(
|
|
1671
|
-
this.write(
|
|
2582
|
+
remove(name2) {
|
|
2583
|
+
this.write(name2, "", Date.now() - 864e5, "/");
|
|
1672
2584
|
}
|
|
1673
2585
|
}
|
|
1674
2586
|
) : (
|
|
@@ -1684,22 +2596,58 @@ const cookies = platform.hasStandardBrowserEnv ? (
|
|
|
1684
2596
|
}
|
|
1685
2597
|
);
|
|
1686
2598
|
function isAbsoluteURL(url) {
|
|
2599
|
+
if (typeof url !== "string") {
|
|
2600
|
+
return false;
|
|
2601
|
+
}
|
|
1687
2602
|
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
|
1688
2603
|
}
|
|
1689
2604
|
function combineURLs(baseURL, relativeURL) {
|
|
1690
2605
|
return relativeURL ? baseURL.replace(/\/?\/$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
|
|
1691
2606
|
}
|
|
1692
|
-
|
|
2607
|
+
const malformedHttpProtocol = /^https?:(?!\/\/)/i;
|
|
2608
|
+
const httpProtocolControlCharacters = /[\t\n\r]/g;
|
|
2609
|
+
function stripLeadingC0ControlOrSpace(url) {
|
|
2610
|
+
let i = 0;
|
|
2611
|
+
while (i < url.length && url.charCodeAt(i) <= 32) {
|
|
2612
|
+
i++;
|
|
2613
|
+
}
|
|
2614
|
+
return url.slice(i);
|
|
2615
|
+
}
|
|
2616
|
+
function normalizeURLForProtocolCheck(url) {
|
|
2617
|
+
return stripLeadingC0ControlOrSpace(url).replace(httpProtocolControlCharacters, "");
|
|
2618
|
+
}
|
|
2619
|
+
function assertValidHttpProtocolURL(url, config2) {
|
|
2620
|
+
if (typeof url === "string" && malformedHttpProtocol.test(normalizeURLForProtocolCheck(url))) {
|
|
2621
|
+
throw new AxiosError$1(
|
|
2622
|
+
'Invalid URL: missing "//" after protocol',
|
|
2623
|
+
AxiosError$1.ERR_INVALID_URL,
|
|
2624
|
+
config2
|
|
2625
|
+
);
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls, config2) {
|
|
2629
|
+
assertValidHttpProtocolURL(requestedURL, config2);
|
|
1693
2630
|
let isRelativeUrl = !isAbsoluteURL(requestedURL);
|
|
1694
|
-
if (baseURL && (isRelativeUrl || allowAbsoluteUrls
|
|
2631
|
+
if (baseURL && (isRelativeUrl || allowAbsoluteUrls === false)) {
|
|
2632
|
+
assertValidHttpProtocolURL(baseURL, config2);
|
|
1695
2633
|
return combineURLs(baseURL, requestedURL);
|
|
1696
2634
|
}
|
|
1697
2635
|
return requestedURL;
|
|
1698
2636
|
}
|
|
1699
2637
|
const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? { ...thing } : thing;
|
|
1700
2638
|
function mergeConfig$1(config1, config2) {
|
|
2639
|
+
config1 = config1 || {};
|
|
1701
2640
|
config2 = config2 || {};
|
|
1702
|
-
const config3 =
|
|
2641
|
+
const config3 = /* @__PURE__ */ Object.create(null);
|
|
2642
|
+
Object.defineProperty(config3, "hasOwnProperty", {
|
|
2643
|
+
// Null-proto descriptor so a polluted Object.prototype.get cannot turn
|
|
2644
|
+
// this data descriptor into an accessor descriptor on the way in.
|
|
2645
|
+
__proto__: null,
|
|
2646
|
+
value: Object.prototype.hasOwnProperty,
|
|
2647
|
+
enumerable: false,
|
|
2648
|
+
writable: true,
|
|
2649
|
+
configurable: true
|
|
2650
|
+
});
|
|
1703
2651
|
function getMergedValue(target, source, prop, caseless) {
|
|
1704
2652
|
if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
|
|
1705
2653
|
return utils$1.merge.call({ caseless }, target, source);
|
|
@@ -1729,10 +2677,27 @@ function mergeConfig$1(config1, config2) {
|
|
|
1729
2677
|
return getMergedValue(void 0, a);
|
|
1730
2678
|
}
|
|
1731
2679
|
}
|
|
2680
|
+
function getMergedTransitionalOption(prop) {
|
|
2681
|
+
const transitional2 = utils$1.hasOwnProp(config2, "transitional") ? config2.transitional : void 0;
|
|
2682
|
+
if (!utils$1.isUndefined(transitional2)) {
|
|
2683
|
+
if (utils$1.isPlainObject(transitional2)) {
|
|
2684
|
+
if (utils$1.hasOwnProp(transitional2, prop)) {
|
|
2685
|
+
return transitional2[prop];
|
|
2686
|
+
}
|
|
2687
|
+
} else {
|
|
2688
|
+
return void 0;
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
const transitional1 = utils$1.hasOwnProp(config1, "transitional") ? config1.transitional : void 0;
|
|
2692
|
+
if (utils$1.isPlainObject(transitional1) && utils$1.hasOwnProp(transitional1, prop)) {
|
|
2693
|
+
return transitional1[prop];
|
|
2694
|
+
}
|
|
2695
|
+
return void 0;
|
|
2696
|
+
}
|
|
1732
2697
|
function mergeDirectKeys(a, b, prop) {
|
|
1733
|
-
if (prop
|
|
2698
|
+
if (utils$1.hasOwnProp(config2, prop)) {
|
|
1734
2699
|
return getMergedValue(a, b);
|
|
1735
|
-
} else if (prop
|
|
2700
|
+
} else if (utils$1.hasOwnProp(config1, prop)) {
|
|
1736
2701
|
return getMergedValue(void 0, a);
|
|
1737
2702
|
}
|
|
1738
2703
|
}
|
|
@@ -1763,44 +2728,87 @@ function mergeConfig$1(config1, config2) {
|
|
|
1763
2728
|
httpsAgent: defaultToConfig2,
|
|
1764
2729
|
cancelToken: defaultToConfig2,
|
|
1765
2730
|
socketPath: defaultToConfig2,
|
|
2731
|
+
allowedSocketPaths: defaultToConfig2,
|
|
1766
2732
|
responseEncoding: defaultToConfig2,
|
|
1767
2733
|
validateStatus: mergeDirectKeys,
|
|
1768
2734
|
headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
|
|
1769
2735
|
};
|
|
1770
2736
|
utils$1.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
|
|
1771
|
-
|
|
1772
|
-
const
|
|
2737
|
+
if (prop === "__proto__" || prop === "constructor" || prop === "prototype") return;
|
|
2738
|
+
const merge2 = utils$1.hasOwnProp(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties;
|
|
2739
|
+
const a = utils$1.hasOwnProp(config1, prop) ? config1[prop] : void 0;
|
|
2740
|
+
const b = utils$1.hasOwnProp(config2, prop) ? config2[prop] : void 0;
|
|
2741
|
+
const configValue = merge2(a, b, prop);
|
|
1773
2742
|
utils$1.isUndefined(configValue) && merge2 !== mergeDirectKeys || (config3[prop] = configValue);
|
|
1774
2743
|
});
|
|
2744
|
+
if (utils$1.hasOwnProp(config2, "validateStatus") && utils$1.isUndefined(config2.validateStatus) && getMergedTransitionalOption("validateStatusUndefinedResolves") === false) {
|
|
2745
|
+
if (utils$1.hasOwnProp(config1, "validateStatus")) {
|
|
2746
|
+
config3.validateStatus = getMergedValue(void 0, config1.validateStatus);
|
|
2747
|
+
} else {
|
|
2748
|
+
delete config3.validateStatus;
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
1775
2751
|
return config3;
|
|
1776
2752
|
}
|
|
1777
|
-
const
|
|
2753
|
+
const FORM_DATA_CONTENT_HEADERS = ["content-type", "content-length"];
|
|
2754
|
+
function setFormDataHeaders(headers, formHeaders, policy) {
|
|
2755
|
+
if (policy !== "content-only") {
|
|
2756
|
+
headers.set(formHeaders);
|
|
2757
|
+
return;
|
|
2758
|
+
}
|
|
2759
|
+
Object.entries(formHeaders || {}).forEach(([key, val]) => {
|
|
2760
|
+
if (FORM_DATA_CONTENT_HEADERS.includes(key.toLowerCase())) {
|
|
2761
|
+
headers.set(key, val);
|
|
2762
|
+
}
|
|
2763
|
+
});
|
|
2764
|
+
}
|
|
2765
|
+
const encodeUTF8$1 = (str2) => encodeURIComponent(str2).replace(
|
|
2766
|
+
/%([0-9A-F]{2})/gi,
|
|
2767
|
+
(_, hex) => String.fromCharCode(parseInt(hex, 16))
|
|
2768
|
+
);
|
|
2769
|
+
function resolveConfig(config2) {
|
|
1778
2770
|
const newConfig = mergeConfig$1({}, config2);
|
|
1779
|
-
|
|
2771
|
+
const own2 = (key) => utils$1.hasOwnProp(newConfig, key) ? newConfig[key] : void 0;
|
|
2772
|
+
const data = own2("data");
|
|
2773
|
+
let withXSRFToken = own2("withXSRFToken");
|
|
2774
|
+
const xsrfHeaderName = own2("xsrfHeaderName");
|
|
2775
|
+
const xsrfCookieName = own2("xsrfCookieName");
|
|
2776
|
+
let headers = own2("headers");
|
|
2777
|
+
const auth = own2("auth");
|
|
2778
|
+
const baseURL = own2("baseURL");
|
|
2779
|
+
const allowAbsoluteUrls = own2("allowAbsoluteUrls");
|
|
2780
|
+
const url = own2("url");
|
|
1780
2781
|
newConfig.headers = headers = AxiosHeaders$1.from(headers);
|
|
1781
|
-
newConfig.url = buildURL(
|
|
2782
|
+
newConfig.url = buildURL(
|
|
2783
|
+
buildFullPath(baseURL, url, allowAbsoluteUrls, newConfig),
|
|
2784
|
+
own2("params"),
|
|
2785
|
+
own2("paramsSerializer")
|
|
2786
|
+
);
|
|
1782
2787
|
if (auth) {
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
2788
|
+
const username = utils$1.getSafeProp(auth, "username") || "";
|
|
2789
|
+
const password = utils$1.getSafeProp(auth, "password") || "";
|
|
2790
|
+
try {
|
|
2791
|
+
headers.set(
|
|
2792
|
+
"Authorization",
|
|
2793
|
+
"Basic " + btoa(username + ":" + (password ? encodeUTF8$1(password) : ""))
|
|
2794
|
+
);
|
|
2795
|
+
} catch (e) {
|
|
2796
|
+
throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_OPTION_VALUE, config2);
|
|
2797
|
+
}
|
|
1787
2798
|
}
|
|
1788
2799
|
if (utils$1.isFormData(data)) {
|
|
1789
|
-
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
|
2800
|
+
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv || utils$1.isReactNative(data)) {
|
|
1790
2801
|
headers.setContentType(void 0);
|
|
1791
2802
|
} else if (utils$1.isFunction(data.getHeaders)) {
|
|
1792
|
-
|
|
1793
|
-
const allowedHeaders = ["content-type", "content-length"];
|
|
1794
|
-
Object.entries(formHeaders).forEach(([key, val]) => {
|
|
1795
|
-
if (allowedHeaders.includes(key.toLowerCase())) {
|
|
1796
|
-
headers.set(key, val);
|
|
1797
|
-
}
|
|
1798
|
-
});
|
|
2803
|
+
setFormDataHeaders(headers, data.getHeaders(), own2("formDataHeaderPolicy"));
|
|
1799
2804
|
}
|
|
1800
2805
|
}
|
|
1801
2806
|
if (platform.hasStandardBrowserEnv) {
|
|
1802
|
-
|
|
1803
|
-
|
|
2807
|
+
if (utils$1.isFunction(withXSRFToken)) {
|
|
2808
|
+
withXSRFToken = withXSRFToken(newConfig);
|
|
2809
|
+
}
|
|
2810
|
+
const shouldSendXSRF = withXSRFToken === true || withXSRFToken == null && isURLSameOrigin(newConfig.url);
|
|
2811
|
+
if (shouldSendXSRF) {
|
|
1804
2812
|
const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
|
|
1805
2813
|
if (xsrfValue) {
|
|
1806
2814
|
headers.set(xsrfHeaderName, xsrfValue);
|
|
@@ -1808,7 +2816,7 @@ const resolveConfig = (config2) => {
|
|
|
1808
2816
|
}
|
|
1809
2817
|
}
|
|
1810
2818
|
return newConfig;
|
|
1811
|
-
}
|
|
2819
|
+
}
|
|
1812
2820
|
const isXHRAdapterSupported = typeof XMLHttpRequest !== "undefined";
|
|
1813
2821
|
const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
1814
2822
|
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
@@ -1844,13 +2852,17 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1844
2852
|
config: config2,
|
|
1845
2853
|
request
|
|
1846
2854
|
};
|
|
1847
|
-
settle(
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
2855
|
+
settle(
|
|
2856
|
+
function _resolve(value) {
|
|
2857
|
+
resolve(value);
|
|
2858
|
+
done();
|
|
2859
|
+
},
|
|
2860
|
+
function _reject(err) {
|
|
2861
|
+
reject(err);
|
|
2862
|
+
done();
|
|
2863
|
+
},
|
|
2864
|
+
response
|
|
2865
|
+
);
|
|
1854
2866
|
request = null;
|
|
1855
2867
|
}
|
|
1856
2868
|
if ("onloadend" in request) {
|
|
@@ -1860,7 +2872,7 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1860
2872
|
if (!request || request.readyState !== 4) {
|
|
1861
2873
|
return;
|
|
1862
2874
|
}
|
|
1863
|
-
if (request.status === 0 && !(request.responseURL && request.responseURL.
|
|
2875
|
+
if (request.status === 0 && !(request.responseURL && request.responseURL.startsWith("file:"))) {
|
|
1864
2876
|
return;
|
|
1865
2877
|
}
|
|
1866
2878
|
setTimeout(onloadend);
|
|
@@ -1871,6 +2883,7 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1871
2883
|
return;
|
|
1872
2884
|
}
|
|
1873
2885
|
reject(new AxiosError$1("Request aborted", AxiosError$1.ECONNABORTED, config2, request));
|
|
2886
|
+
done();
|
|
1874
2887
|
request = null;
|
|
1875
2888
|
};
|
|
1876
2889
|
request.onerror = function handleError(event) {
|
|
@@ -1878,6 +2891,7 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1878
2891
|
const err = new AxiosError$1(msg, AxiosError$1.ERR_NETWORK, config2, request);
|
|
1879
2892
|
err.event = event || null;
|
|
1880
2893
|
reject(err);
|
|
2894
|
+
done();
|
|
1881
2895
|
request = null;
|
|
1882
2896
|
};
|
|
1883
2897
|
request.ontimeout = function handleTimeout() {
|
|
@@ -1886,17 +2900,20 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1886
2900
|
if (_config.timeoutErrorMessage) {
|
|
1887
2901
|
timeoutErrorMessage = _config.timeoutErrorMessage;
|
|
1888
2902
|
}
|
|
1889
|
-
reject(
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
2903
|
+
reject(
|
|
2904
|
+
new AxiosError$1(
|
|
2905
|
+
timeoutErrorMessage,
|
|
2906
|
+
transitional2.clarifyTimeoutError ? AxiosError$1.ETIMEDOUT : AxiosError$1.ECONNABORTED,
|
|
2907
|
+
config2,
|
|
2908
|
+
request
|
|
2909
|
+
)
|
|
2910
|
+
);
|
|
2911
|
+
done();
|
|
1895
2912
|
request = null;
|
|
1896
2913
|
};
|
|
1897
2914
|
requestData === void 0 && requestHeaders.setContentType(null);
|
|
1898
2915
|
if ("setRequestHeader" in request) {
|
|
1899
|
-
utils$1.forEach(requestHeaders
|
|
2916
|
+
utils$1.forEach(toByteStringHeaderObject(requestHeaders), function setRequestHeader(val, key) {
|
|
1900
2917
|
request.setRequestHeader(key, val);
|
|
1901
2918
|
});
|
|
1902
2919
|
}
|
|
@@ -1922,6 +2939,7 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1922
2939
|
}
|
|
1923
2940
|
reject(!cancel || cancel.type ? new CanceledError$1(null, config2, request) : cancel);
|
|
1924
2941
|
request.abort();
|
|
2942
|
+
done();
|
|
1925
2943
|
request = null;
|
|
1926
2944
|
};
|
|
1927
2945
|
_config.cancelToken && _config.cancelToken.subscribe(onCanceled);
|
|
@@ -1930,45 +2948,56 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1930
2948
|
}
|
|
1931
2949
|
}
|
|
1932
2950
|
const protocol = parseProtocol(_config.url);
|
|
1933
|
-
if (protocol && platform.protocols.
|
|
1934
|
-
reject(
|
|
2951
|
+
if (protocol && !platform.protocols.includes(protocol)) {
|
|
2952
|
+
reject(
|
|
2953
|
+
new AxiosError$1(
|
|
2954
|
+
"Unsupported protocol " + protocol + ":",
|
|
2955
|
+
AxiosError$1.ERR_BAD_REQUEST,
|
|
2956
|
+
config2
|
|
2957
|
+
)
|
|
2958
|
+
);
|
|
2959
|
+
done();
|
|
1935
2960
|
return;
|
|
1936
2961
|
}
|
|
1937
2962
|
request.send(requestData || null);
|
|
1938
2963
|
});
|
|
1939
2964
|
};
|
|
1940
2965
|
const composeSignals = (signals, timeout) => {
|
|
1941
|
-
|
|
1942
|
-
if (timeout
|
|
1943
|
-
|
|
1944
|
-
let aborted;
|
|
1945
|
-
const onabort = function(reason) {
|
|
1946
|
-
if (!aborted) {
|
|
1947
|
-
aborted = true;
|
|
1948
|
-
unsubscribe();
|
|
1949
|
-
const err = reason instanceof Error ? reason : this.reason;
|
|
1950
|
-
controller2.abort(err instanceof AxiosError$1 ? err : new CanceledError$1(err instanceof Error ? err.message : err));
|
|
1951
|
-
}
|
|
1952
|
-
};
|
|
1953
|
-
let timer = timeout && setTimeout(() => {
|
|
1954
|
-
timer = null;
|
|
1955
|
-
onabort(new AxiosError$1(`timeout ${timeout} of ms exceeded`, AxiosError$1.ETIMEDOUT));
|
|
1956
|
-
}, timeout);
|
|
1957
|
-
const unsubscribe = () => {
|
|
1958
|
-
if (signals) {
|
|
1959
|
-
timer && clearTimeout(timer);
|
|
1960
|
-
timer = null;
|
|
1961
|
-
signals.forEach((signal2) => {
|
|
1962
|
-
signal2.unsubscribe ? signal2.unsubscribe(onabort) : signal2.removeEventListener("abort", onabort);
|
|
1963
|
-
});
|
|
1964
|
-
signals = null;
|
|
1965
|
-
}
|
|
1966
|
-
};
|
|
1967
|
-
signals.forEach((signal2) => signal2.addEventListener("abort", onabort));
|
|
1968
|
-
const { signal } = controller2;
|
|
1969
|
-
signal.unsubscribe = () => utils$1.asap(unsubscribe);
|
|
1970
|
-
return signal;
|
|
2966
|
+
signals = signals ? signals.filter(Boolean) : [];
|
|
2967
|
+
if (!timeout && !signals.length) {
|
|
2968
|
+
return;
|
|
1971
2969
|
}
|
|
2970
|
+
const controller2 = new AbortController();
|
|
2971
|
+
let aborted = false;
|
|
2972
|
+
const onabort = function(reason) {
|
|
2973
|
+
if (!aborted) {
|
|
2974
|
+
aborted = true;
|
|
2975
|
+
unsubscribe();
|
|
2976
|
+
const err = reason instanceof Error ? reason : this.reason;
|
|
2977
|
+
controller2.abort(
|
|
2978
|
+
err instanceof AxiosError$1 ? err : new CanceledError$1(err instanceof Error ? err.message : err)
|
|
2979
|
+
);
|
|
2980
|
+
}
|
|
2981
|
+
};
|
|
2982
|
+
let timer = timeout && setTimeout(() => {
|
|
2983
|
+
timer = null;
|
|
2984
|
+
onabort(new AxiosError$1(`timeout of ${timeout}ms exceeded`, AxiosError$1.ETIMEDOUT));
|
|
2985
|
+
}, timeout);
|
|
2986
|
+
const unsubscribe = () => {
|
|
2987
|
+
if (!signals) {
|
|
2988
|
+
return;
|
|
2989
|
+
}
|
|
2990
|
+
timer && clearTimeout(timer);
|
|
2991
|
+
timer = null;
|
|
2992
|
+
signals.forEach((signal2) => {
|
|
2993
|
+
signal2.unsubscribe ? signal2.unsubscribe(onabort) : signal2.removeEventListener("abort", onabort);
|
|
2994
|
+
});
|
|
2995
|
+
signals = null;
|
|
2996
|
+
};
|
|
2997
|
+
signals.forEach((signal2) => signal2.addEventListener("abort", onabort, { once: true }));
|
|
2998
|
+
const { signal } = controller2;
|
|
2999
|
+
signal.unsubscribe = () => utils$1.asap(unsubscribe);
|
|
3000
|
+
return signal;
|
|
1972
3001
|
};
|
|
1973
3002
|
const streamChunk = function* (chunk, chunkSize) {
|
|
1974
3003
|
let len = chunk.byteLength;
|
|
@@ -2017,44 +3046,127 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
|
|
2017
3046
|
onFinish && onFinish(e);
|
|
2018
3047
|
}
|
|
2019
3048
|
};
|
|
2020
|
-
return new ReadableStream(
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
3049
|
+
return new ReadableStream(
|
|
3050
|
+
{
|
|
3051
|
+
async pull(controller2) {
|
|
3052
|
+
try {
|
|
3053
|
+
const { done: done2, value } = await iterator2.next();
|
|
3054
|
+
if (done2) {
|
|
3055
|
+
_onFinish();
|
|
3056
|
+
controller2.close();
|
|
3057
|
+
return;
|
|
3058
|
+
}
|
|
3059
|
+
let len = value.byteLength;
|
|
3060
|
+
if (onProgress) {
|
|
3061
|
+
let loadedBytes = bytes += len;
|
|
3062
|
+
onProgress(loadedBytes);
|
|
3063
|
+
}
|
|
3064
|
+
controller2.enqueue(new Uint8Array(value));
|
|
3065
|
+
} catch (err) {
|
|
3066
|
+
_onFinish(err);
|
|
3067
|
+
throw err;
|
|
2033
3068
|
}
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
_onFinish(
|
|
2037
|
-
|
|
3069
|
+
},
|
|
3070
|
+
cancel(reason) {
|
|
3071
|
+
_onFinish(reason);
|
|
3072
|
+
return iterator2.return();
|
|
2038
3073
|
}
|
|
2039
3074
|
},
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
return iterator2.return();
|
|
3075
|
+
{
|
|
3076
|
+
highWaterMark: 2
|
|
2043
3077
|
}
|
|
2044
|
-
|
|
2045
|
-
highWaterMark: 2
|
|
2046
|
-
});
|
|
3078
|
+
);
|
|
2047
3079
|
};
|
|
3080
|
+
const isHexDigit = (charCode) => charCode >= 48 && charCode <= 57 || charCode >= 65 && charCode <= 70 || charCode >= 97 && charCode <= 102;
|
|
3081
|
+
const isPercentEncodedByte = (str2, i, len) => i + 2 < len && isHexDigit(str2.charCodeAt(i + 1)) && isHexDigit(str2.charCodeAt(i + 2));
|
|
3082
|
+
function estimateDataURLDecodedBytes(url) {
|
|
3083
|
+
if (!url || typeof url !== "string") return 0;
|
|
3084
|
+
if (!url.startsWith("data:")) return 0;
|
|
3085
|
+
const comma = url.indexOf(",");
|
|
3086
|
+
if (comma < 0) return 0;
|
|
3087
|
+
const meta = url.slice(5, comma);
|
|
3088
|
+
const body = url.slice(comma + 1);
|
|
3089
|
+
const isBase64 = /;base64/i.test(meta);
|
|
3090
|
+
if (isBase64) {
|
|
3091
|
+
let effectiveLen = body.length;
|
|
3092
|
+
const len = body.length;
|
|
3093
|
+
for (let i = 0; i < len; i++) {
|
|
3094
|
+
if (body.charCodeAt(i) === 37 && i + 2 < len) {
|
|
3095
|
+
const a = body.charCodeAt(i + 1);
|
|
3096
|
+
const b = body.charCodeAt(i + 2);
|
|
3097
|
+
const isHex = isHexDigit(a) && isHexDigit(b);
|
|
3098
|
+
if (isHex) {
|
|
3099
|
+
effectiveLen -= 2;
|
|
3100
|
+
i += 2;
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
let pad = 0;
|
|
3105
|
+
let idx = len - 1;
|
|
3106
|
+
const tailIsPct3D = (j) => j >= 2 && body.charCodeAt(j - 2) === 37 && // '%'
|
|
3107
|
+
body.charCodeAt(j - 1) === 51 && // '3'
|
|
3108
|
+
(body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100);
|
|
3109
|
+
if (idx >= 0) {
|
|
3110
|
+
if (body.charCodeAt(idx) === 61) {
|
|
3111
|
+
pad++;
|
|
3112
|
+
idx--;
|
|
3113
|
+
} else if (tailIsPct3D(idx)) {
|
|
3114
|
+
pad++;
|
|
3115
|
+
idx -= 3;
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
if (pad === 1 && idx >= 0) {
|
|
3119
|
+
if (body.charCodeAt(idx) === 61) {
|
|
3120
|
+
pad++;
|
|
3121
|
+
} else if (tailIsPct3D(idx)) {
|
|
3122
|
+
pad++;
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
const groups = Math.floor(effectiveLen / 4);
|
|
3126
|
+
const bytes2 = groups * 3 - (pad || 0);
|
|
3127
|
+
return bytes2 > 0 ? bytes2 : 0;
|
|
3128
|
+
}
|
|
3129
|
+
let bytes = 0;
|
|
3130
|
+
for (let i = 0, len = body.length; i < len; i++) {
|
|
3131
|
+
const c = body.charCodeAt(i);
|
|
3132
|
+
if (c === 37 && isPercentEncodedByte(body, i, len)) {
|
|
3133
|
+
bytes += 1;
|
|
3134
|
+
i += 2;
|
|
3135
|
+
} else if (c < 128) {
|
|
3136
|
+
bytes += 1;
|
|
3137
|
+
} else if (c < 2048) {
|
|
3138
|
+
bytes += 2;
|
|
3139
|
+
} else if (c >= 55296 && c <= 56319 && i + 1 < len) {
|
|
3140
|
+
const next = body.charCodeAt(i + 1);
|
|
3141
|
+
if (next >= 56320 && next <= 57343) {
|
|
3142
|
+
bytes += 4;
|
|
3143
|
+
i++;
|
|
3144
|
+
} else {
|
|
3145
|
+
bytes += 3;
|
|
3146
|
+
}
|
|
3147
|
+
} else {
|
|
3148
|
+
bytes += 3;
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
return bytes;
|
|
3152
|
+
}
|
|
3153
|
+
const VERSION$1 = "1.18.1";
|
|
2048
3154
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
2049
3155
|
const { isFunction } = utils$1;
|
|
2050
|
-
const
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
const {
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
}
|
|
3156
|
+
const encodeUTF8 = (str2) => encodeURIComponent(str2).replace(
|
|
3157
|
+
/%([0-9A-F]{2})/gi,
|
|
3158
|
+
(_, hex) => String.fromCharCode(parseInt(hex, 16))
|
|
3159
|
+
);
|
|
3160
|
+
const decodeURIComponentSafe = (value) => {
|
|
3161
|
+
if (!utils$1.isString(value)) {
|
|
3162
|
+
return value;
|
|
3163
|
+
}
|
|
3164
|
+
try {
|
|
3165
|
+
return decodeURIComponent(value);
|
|
3166
|
+
} catch (error) {
|
|
3167
|
+
return value;
|
|
3168
|
+
}
|
|
3169
|
+
};
|
|
2058
3170
|
const test = (fn, ...args) => {
|
|
2059
3171
|
try {
|
|
2060
3172
|
return !!fn(...args);
|
|
@@ -2062,10 +3174,27 @@ const test = (fn, ...args) => {
|
|
|
2062
3174
|
return false;
|
|
2063
3175
|
}
|
|
2064
3176
|
};
|
|
3177
|
+
const maybeWithAuthCredentials = (url) => {
|
|
3178
|
+
const protocolIndex = url.indexOf("://");
|
|
3179
|
+
let urlToCheck = url;
|
|
3180
|
+
if (protocolIndex !== -1) {
|
|
3181
|
+
urlToCheck = urlToCheck.slice(protocolIndex + 3);
|
|
3182
|
+
}
|
|
3183
|
+
return urlToCheck.includes("@") || urlToCheck.includes(":");
|
|
3184
|
+
};
|
|
2065
3185
|
const factory = (env) => {
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
3186
|
+
const globalObject = utils$1.global !== void 0 && utils$1.global !== null ? utils$1.global : globalThis;
|
|
3187
|
+
const { ReadableStream: ReadableStream2, TextEncoder } = globalObject;
|
|
3188
|
+
env = utils$1.merge.call(
|
|
3189
|
+
{
|
|
3190
|
+
skipUndefined: true
|
|
3191
|
+
},
|
|
3192
|
+
{
|
|
3193
|
+
Request: globalObject.Request,
|
|
3194
|
+
Response: globalObject.Response
|
|
3195
|
+
},
|
|
3196
|
+
env
|
|
3197
|
+
);
|
|
2069
3198
|
const { fetch: envFetch, Request, Response } = env;
|
|
2070
3199
|
const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === "function";
|
|
2071
3200
|
const isRequestSupported = isFunction(Request);
|
|
@@ -2073,18 +3202,22 @@ const factory = (env) => {
|
|
|
2073
3202
|
if (!isFetchSupported) {
|
|
2074
3203
|
return false;
|
|
2075
3204
|
}
|
|
2076
|
-
const isReadableStreamSupported = isFetchSupported && isFunction(
|
|
2077
|
-
const encodeText = isFetchSupported && (typeof TextEncoder === "function" ? /* @__PURE__ */ ((encoder) => (
|
|
3205
|
+
const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream2);
|
|
3206
|
+
const encodeText = isFetchSupported && (typeof TextEncoder === "function" ? /* @__PURE__ */ ((encoder) => (str2) => encoder.encode(str2))(new TextEncoder()) : async (str2) => new Uint8Array(await new Request(str2).arrayBuffer()));
|
|
2078
3207
|
const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
|
2079
3208
|
let duplexAccessed = false;
|
|
2080
|
-
const
|
|
2081
|
-
body: new
|
|
3209
|
+
const request = new Request(platform.origin, {
|
|
3210
|
+
body: new ReadableStream2(),
|
|
2082
3211
|
method: "POST",
|
|
2083
3212
|
get duplex() {
|
|
2084
3213
|
duplexAccessed = true;
|
|
2085
3214
|
return "half";
|
|
2086
3215
|
}
|
|
2087
|
-
})
|
|
3216
|
+
});
|
|
3217
|
+
const hasContentType = request.headers.has("Content-Type");
|
|
3218
|
+
if (request.body != null) {
|
|
3219
|
+
request.body.cancel();
|
|
3220
|
+
}
|
|
2088
3221
|
return duplexAccessed && !hasContentType;
|
|
2089
3222
|
});
|
|
2090
3223
|
const supportsResponseStream = isResponseSupported && isReadableStreamSupported && test(() => utils$1.isReadableStream(new Response("").body));
|
|
@@ -2098,7 +3231,11 @@ const factory = (env) => {
|
|
|
2098
3231
|
if (method) {
|
|
2099
3232
|
return method.call(res);
|
|
2100
3233
|
}
|
|
2101
|
-
throw new AxiosError$1(
|
|
3234
|
+
throw new AxiosError$1(
|
|
3235
|
+
`Response type '${type}' is not supported`,
|
|
3236
|
+
AxiosError$1.ERR_NOT_SUPPORT,
|
|
3237
|
+
config2
|
|
3238
|
+
);
|
|
2102
3239
|
});
|
|
2103
3240
|
});
|
|
2104
3241
|
})();
|
|
@@ -2143,63 +3280,189 @@ const factory = (env) => {
|
|
|
2143
3280
|
responseType,
|
|
2144
3281
|
headers,
|
|
2145
3282
|
withCredentials = "same-origin",
|
|
2146
|
-
fetchOptions
|
|
3283
|
+
fetchOptions,
|
|
3284
|
+
maxContentLength,
|
|
3285
|
+
maxBodyLength
|
|
2147
3286
|
} = resolveConfig(config2);
|
|
3287
|
+
const hasMaxContentLength = utils$1.isNumber(maxContentLength) && maxContentLength > -1;
|
|
3288
|
+
const hasMaxBodyLength = utils$1.isNumber(maxBodyLength) && maxBodyLength > -1;
|
|
3289
|
+
const own2 = (key) => utils$1.hasOwnProp(config2, key) ? config2[key] : void 0;
|
|
2148
3290
|
let _fetch = envFetch || fetch;
|
|
2149
3291
|
responseType = responseType ? (responseType + "").toLowerCase() : "text";
|
|
2150
|
-
let composedSignal = composeSignals(
|
|
3292
|
+
let composedSignal = composeSignals(
|
|
3293
|
+
[signal, cancelToken && cancelToken.toAbortSignal()],
|
|
3294
|
+
timeout
|
|
3295
|
+
);
|
|
2151
3296
|
let request = null;
|
|
2152
3297
|
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
2153
3298
|
composedSignal.unsubscribe();
|
|
2154
3299
|
});
|
|
2155
3300
|
let requestContentLength;
|
|
3301
|
+
let pendingBodyError = null;
|
|
3302
|
+
const maxBodyLengthError = () => new AxiosError$1(
|
|
3303
|
+
"Request body larger than maxBodyLength limit",
|
|
3304
|
+
AxiosError$1.ERR_BAD_REQUEST,
|
|
3305
|
+
config2,
|
|
3306
|
+
request
|
|
3307
|
+
);
|
|
2156
3308
|
try {
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
3309
|
+
let auth = void 0;
|
|
3310
|
+
const configAuth = own2("auth");
|
|
3311
|
+
if (configAuth) {
|
|
3312
|
+
const username = utils$1.getSafeProp(configAuth, "username") || "";
|
|
3313
|
+
const password = utils$1.getSafeProp(configAuth, "password") || "";
|
|
3314
|
+
auth = {
|
|
3315
|
+
username,
|
|
3316
|
+
password
|
|
3317
|
+
};
|
|
3318
|
+
}
|
|
3319
|
+
if (maybeWithAuthCredentials(url)) {
|
|
3320
|
+
const parsedURL = new URL(url, platform.origin);
|
|
3321
|
+
if (!auth && (parsedURL.username || parsedURL.password)) {
|
|
3322
|
+
const urlUsername = decodeURIComponentSafe(parsedURL.username);
|
|
3323
|
+
const urlPassword = decodeURIComponentSafe(parsedURL.password);
|
|
3324
|
+
auth = {
|
|
3325
|
+
username: urlUsername,
|
|
3326
|
+
password: urlPassword
|
|
3327
|
+
};
|
|
2166
3328
|
}
|
|
2167
|
-
if (
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
3329
|
+
if (parsedURL.username || parsedURL.password) {
|
|
3330
|
+
parsedURL.username = "";
|
|
3331
|
+
parsedURL.password = "";
|
|
3332
|
+
url = parsedURL.href;
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3335
|
+
if (auth) {
|
|
3336
|
+
headers.delete("authorization");
|
|
3337
|
+
headers.set(
|
|
3338
|
+
"Authorization",
|
|
3339
|
+
"Basic " + btoa(encodeUTF8((auth.username || "") + ":" + (auth.password || "")))
|
|
3340
|
+
);
|
|
3341
|
+
}
|
|
3342
|
+
if (hasMaxContentLength && typeof url === "string" && url.startsWith("data:")) {
|
|
3343
|
+
const estimated = estimateDataURLDecodedBytes(url);
|
|
3344
|
+
if (estimated > maxContentLength) {
|
|
3345
|
+
throw new AxiosError$1(
|
|
3346
|
+
"maxContentLength size of " + maxContentLength + " exceeded",
|
|
3347
|
+
AxiosError$1.ERR_BAD_RESPONSE,
|
|
3348
|
+
config2,
|
|
3349
|
+
request
|
|
2171
3350
|
);
|
|
2172
|
-
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
|
2173
3351
|
}
|
|
2174
3352
|
}
|
|
3353
|
+
if (hasMaxBodyLength && method !== "get" && method !== "head") {
|
|
3354
|
+
const outboundLength = await getBodyLength(data);
|
|
3355
|
+
if (typeof outboundLength === "number" && isFinite(outboundLength)) {
|
|
3356
|
+
requestContentLength = outboundLength;
|
|
3357
|
+
if (outboundLength > maxBodyLength) {
|
|
3358
|
+
throw maxBodyLengthError();
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
}
|
|
3362
|
+
const mustEnforceStreamBody = hasMaxBodyLength && (utils$1.isReadableStream(data) || utils$1.isStream(data));
|
|
3363
|
+
const trackRequestStream = (stream, onProgress, flush) => trackStream(
|
|
3364
|
+
stream,
|
|
3365
|
+
DEFAULT_CHUNK_SIZE,
|
|
3366
|
+
(loadedBytes) => {
|
|
3367
|
+
if (hasMaxBodyLength && loadedBytes > maxBodyLength) {
|
|
3368
|
+
throw pendingBodyError = maxBodyLengthError();
|
|
3369
|
+
}
|
|
3370
|
+
onProgress && onProgress(loadedBytes);
|
|
3371
|
+
},
|
|
3372
|
+
flush
|
|
3373
|
+
);
|
|
3374
|
+
if (supportsRequestStream && method !== "get" && method !== "head" && (onUploadProgress || mustEnforceStreamBody)) {
|
|
3375
|
+
requestContentLength = requestContentLength == null ? await resolveBodyLength(headers, data) : requestContentLength;
|
|
3376
|
+
if (requestContentLength !== 0 || mustEnforceStreamBody) {
|
|
3377
|
+
let _request = new Request(url, {
|
|
3378
|
+
method: "POST",
|
|
3379
|
+
body: data,
|
|
3380
|
+
duplex: "half"
|
|
3381
|
+
});
|
|
3382
|
+
let contentTypeHeader;
|
|
3383
|
+
if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get("content-type"))) {
|
|
3384
|
+
headers.setContentType(contentTypeHeader);
|
|
3385
|
+
}
|
|
3386
|
+
if (_request.body) {
|
|
3387
|
+
const [onProgress, flush] = onUploadProgress && progressEventDecorator(
|
|
3388
|
+
requestContentLength,
|
|
3389
|
+
progressEventReducer(asyncDecorator(onUploadProgress))
|
|
3390
|
+
) || [];
|
|
3391
|
+
data = trackRequestStream(_request.body, onProgress, flush);
|
|
3392
|
+
}
|
|
3393
|
+
}
|
|
3394
|
+
} else if (mustEnforceStreamBody && !isRequestSupported && isReadableStreamSupported && method !== "get" && method !== "head") {
|
|
3395
|
+
data = trackRequestStream(data);
|
|
3396
|
+
} else if (mustEnforceStreamBody && isRequestSupported && !supportsRequestStream && method !== "get" && method !== "head") {
|
|
3397
|
+
throw new AxiosError$1(
|
|
3398
|
+
"Stream request bodies are not supported by the current fetch implementation",
|
|
3399
|
+
AxiosError$1.ERR_NOT_SUPPORT,
|
|
3400
|
+
config2,
|
|
3401
|
+
request
|
|
3402
|
+
);
|
|
3403
|
+
}
|
|
2175
3404
|
if (!utils$1.isString(withCredentials)) {
|
|
2176
3405
|
withCredentials = withCredentials ? "include" : "omit";
|
|
2177
3406
|
}
|
|
2178
3407
|
const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
|
|
3408
|
+
if (utils$1.isFormData(data)) {
|
|
3409
|
+
const contentType = headers.getContentType();
|
|
3410
|
+
if (contentType && /^multipart\/form-data/i.test(contentType) && !/boundary=/i.test(contentType)) {
|
|
3411
|
+
headers.delete("content-type");
|
|
3412
|
+
}
|
|
3413
|
+
}
|
|
3414
|
+
headers.set("User-Agent", "axios/" + VERSION$1, false);
|
|
2179
3415
|
const resolvedOptions = {
|
|
2180
3416
|
...fetchOptions,
|
|
2181
3417
|
signal: composedSignal,
|
|
2182
3418
|
method: method.toUpperCase(),
|
|
2183
|
-
headers: headers.normalize()
|
|
3419
|
+
headers: toByteStringHeaderObject(headers.normalize()),
|
|
2184
3420
|
body: data,
|
|
2185
3421
|
duplex: "half",
|
|
2186
3422
|
credentials: isCredentialsSupported ? withCredentials : void 0
|
|
2187
3423
|
};
|
|
2188
3424
|
request = isRequestSupported && new Request(url, resolvedOptions);
|
|
2189
3425
|
let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
|
|
3426
|
+
const responseHeaders = AxiosHeaders$1.from(response.headers);
|
|
3427
|
+
if (hasMaxContentLength) {
|
|
3428
|
+
const declaredLength = utils$1.toFiniteNumber(responseHeaders.getContentLength());
|
|
3429
|
+
if (declaredLength != null && declaredLength > maxContentLength) {
|
|
3430
|
+
throw new AxiosError$1(
|
|
3431
|
+
"maxContentLength size of " + maxContentLength + " exceeded",
|
|
3432
|
+
AxiosError$1.ERR_BAD_RESPONSE,
|
|
3433
|
+
config2,
|
|
3434
|
+
request
|
|
3435
|
+
);
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
2190
3438
|
const isStreamResponse = supportsResponseStream && (responseType === "stream" || responseType === "response");
|
|
2191
|
-
if (supportsResponseStream && (onDownloadProgress || isStreamResponse && unsubscribe)) {
|
|
3439
|
+
if (supportsResponseStream && response.body && (onDownloadProgress || hasMaxContentLength || isStreamResponse && unsubscribe)) {
|
|
2192
3440
|
const options = {};
|
|
2193
3441
|
["status", "statusText", "headers"].forEach((prop) => {
|
|
2194
3442
|
options[prop] = response[prop];
|
|
2195
3443
|
});
|
|
2196
|
-
const responseContentLength = utils$1.toFiniteNumber(
|
|
3444
|
+
const responseContentLength = utils$1.toFiniteNumber(responseHeaders.getContentLength());
|
|
2197
3445
|
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
|
2198
3446
|
responseContentLength,
|
|
2199
3447
|
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
|
2200
3448
|
) || [];
|
|
3449
|
+
let bytesRead = 0;
|
|
3450
|
+
const onChunkProgress = (loadedBytes) => {
|
|
3451
|
+
if (hasMaxContentLength) {
|
|
3452
|
+
bytesRead = loadedBytes;
|
|
3453
|
+
if (bytesRead > maxContentLength) {
|
|
3454
|
+
throw new AxiosError$1(
|
|
3455
|
+
"maxContentLength size of " + maxContentLength + " exceeded",
|
|
3456
|
+
AxiosError$1.ERR_BAD_RESPONSE,
|
|
3457
|
+
config2,
|
|
3458
|
+
request
|
|
3459
|
+
);
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
onProgress && onProgress(loadedBytes);
|
|
3463
|
+
};
|
|
2201
3464
|
response = new Response(
|
|
2202
|
-
trackStream(response.body, DEFAULT_CHUNK_SIZE,
|
|
3465
|
+
trackStream(response.body, DEFAULT_CHUNK_SIZE, onChunkProgress, () => {
|
|
2203
3466
|
flush && flush();
|
|
2204
3467
|
unsubscribe && unsubscribe();
|
|
2205
3468
|
}),
|
|
@@ -2207,7 +3470,30 @@ const factory = (env) => {
|
|
|
2207
3470
|
);
|
|
2208
3471
|
}
|
|
2209
3472
|
responseType = responseType || "text";
|
|
2210
|
-
let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || "text"](
|
|
3473
|
+
let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || "text"](
|
|
3474
|
+
response,
|
|
3475
|
+
config2
|
|
3476
|
+
);
|
|
3477
|
+
if (hasMaxContentLength && !supportsResponseStream && !isStreamResponse) {
|
|
3478
|
+
let materializedSize;
|
|
3479
|
+
if (responseData != null) {
|
|
3480
|
+
if (typeof responseData.byteLength === "number") {
|
|
3481
|
+
materializedSize = responseData.byteLength;
|
|
3482
|
+
} else if (typeof responseData.size === "number") {
|
|
3483
|
+
materializedSize = responseData.size;
|
|
3484
|
+
} else if (typeof responseData === "string") {
|
|
3485
|
+
materializedSize = typeof TextEncoder === "function" ? new TextEncoder().encode(responseData).byteLength : responseData.length;
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
if (typeof materializedSize === "number" && materializedSize > maxContentLength) {
|
|
3489
|
+
throw new AxiosError$1(
|
|
3490
|
+
"maxContentLength size of " + maxContentLength + " exceeded",
|
|
3491
|
+
AxiosError$1.ERR_BAD_RESPONSE,
|
|
3492
|
+
config2,
|
|
3493
|
+
request
|
|
3494
|
+
);
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
2211
3497
|
!isStreamResponse && unsubscribe && unsubscribe();
|
|
2212
3498
|
return await new Promise((resolve, reject) => {
|
|
2213
3499
|
settle(resolve, reject, {
|
|
@@ -2221,27 +3507,55 @@ const factory = (env) => {
|
|
|
2221
3507
|
});
|
|
2222
3508
|
} catch (err) {
|
|
2223
3509
|
unsubscribe && unsubscribe();
|
|
3510
|
+
if (composedSignal && composedSignal.aborted && composedSignal.reason instanceof AxiosError$1) {
|
|
3511
|
+
const canceledError = composedSignal.reason;
|
|
3512
|
+
canceledError.config = config2;
|
|
3513
|
+
request && (canceledError.request = request);
|
|
3514
|
+
if (err !== canceledError) {
|
|
3515
|
+
Object.defineProperty(canceledError, "cause", {
|
|
3516
|
+
__proto__: null,
|
|
3517
|
+
value: err,
|
|
3518
|
+
writable: true,
|
|
3519
|
+
enumerable: false,
|
|
3520
|
+
configurable: true
|
|
3521
|
+
});
|
|
3522
|
+
}
|
|
3523
|
+
throw canceledError;
|
|
3524
|
+
}
|
|
3525
|
+
if (pendingBodyError) {
|
|
3526
|
+
request && !pendingBodyError.request && (pendingBodyError.request = request);
|
|
3527
|
+
throw pendingBodyError;
|
|
3528
|
+
}
|
|
3529
|
+
if (err instanceof AxiosError$1) {
|
|
3530
|
+
request && !err.request && (err.request = request);
|
|
3531
|
+
throw err;
|
|
3532
|
+
}
|
|
2224
3533
|
if (err && err.name === "TypeError" && /Load failed|fetch/i.test(err.message)) {
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
3534
|
+
const networkError = new AxiosError$1(
|
|
3535
|
+
"Network Error",
|
|
3536
|
+
AxiosError$1.ERR_NETWORK,
|
|
3537
|
+
config2,
|
|
3538
|
+
request,
|
|
3539
|
+
err && err.response
|
|
2230
3540
|
);
|
|
3541
|
+
Object.defineProperty(networkError, "cause", {
|
|
3542
|
+
__proto__: null,
|
|
3543
|
+
value: err.cause || err,
|
|
3544
|
+
writable: true,
|
|
3545
|
+
enumerable: false,
|
|
3546
|
+
configurable: true
|
|
3547
|
+
});
|
|
3548
|
+
throw networkError;
|
|
2231
3549
|
}
|
|
2232
|
-
throw AxiosError$1.from(err, err && err.code, config2, request);
|
|
3550
|
+
throw AxiosError$1.from(err, err && err.code, config2, request, err && err.response);
|
|
2233
3551
|
}
|
|
2234
3552
|
};
|
|
2235
3553
|
};
|
|
2236
3554
|
const seedCache = /* @__PURE__ */ new Map();
|
|
2237
3555
|
const getFetch = (config2) => {
|
|
2238
|
-
let env = config2
|
|
3556
|
+
let env = config2 && config2.env || {};
|
|
2239
3557
|
const { fetch: fetch2, Request, Response } = env;
|
|
2240
|
-
const seeds = [
|
|
2241
|
-
Request,
|
|
2242
|
-
Response,
|
|
2243
|
-
fetch2
|
|
2244
|
-
];
|
|
3558
|
+
const seeds = [Request, Response, fetch2];
|
|
2245
3559
|
let len = seeds.length, i = len, seed, target, map = seedCache;
|
|
2246
3560
|
while (i--) {
|
|
2247
3561
|
seed = seeds[i];
|
|
@@ -2262,48 +3576,57 @@ const knownAdapters = {
|
|
|
2262
3576
|
utils$1.forEach(knownAdapters, (fn, value) => {
|
|
2263
3577
|
if (fn) {
|
|
2264
3578
|
try {
|
|
2265
|
-
Object.defineProperty(fn, "name", { value });
|
|
3579
|
+
Object.defineProperty(fn, "name", { __proto__: null, value });
|
|
2266
3580
|
} catch (e) {
|
|
2267
3581
|
}
|
|
2268
|
-
Object.defineProperty(fn, "adapterName", { value });
|
|
3582
|
+
Object.defineProperty(fn, "adapterName", { __proto__: null, value });
|
|
2269
3583
|
}
|
|
2270
3584
|
});
|
|
2271
3585
|
const renderReason = (reason) => `- ${reason}`;
|
|
2272
3586
|
const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
throw new AxiosError$1(`Unknown adapter '${id}'`);
|
|
2288
|
-
}
|
|
2289
|
-
}
|
|
2290
|
-
if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config2)))) {
|
|
2291
|
-
break;
|
|
3587
|
+
function getAdapter$1(adapters2, config2) {
|
|
3588
|
+
adapters2 = utils$1.isArray(adapters2) ? adapters2 : [adapters2];
|
|
3589
|
+
const { length } = adapters2;
|
|
3590
|
+
let nameOrAdapter;
|
|
3591
|
+
let adapter;
|
|
3592
|
+
const rejectedReasons = {};
|
|
3593
|
+
for (let i = 0; i < length; i++) {
|
|
3594
|
+
nameOrAdapter = adapters2[i];
|
|
3595
|
+
let id;
|
|
3596
|
+
adapter = nameOrAdapter;
|
|
3597
|
+
if (!isResolvedHandle(nameOrAdapter)) {
|
|
3598
|
+
adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
|
3599
|
+
if (adapter === void 0) {
|
|
3600
|
+
throw new AxiosError$1(`Unknown adapter '${id}'`);
|
|
2292
3601
|
}
|
|
2293
|
-
rejectedReasons[id || "#" + i] = adapter;
|
|
2294
3602
|
}
|
|
2295
|
-
if (
|
|
2296
|
-
|
|
2297
|
-
([id, state]) => `adapter ${id} ` + (state === false ? "is not supported by the environment" : "is not available in the build")
|
|
2298
|
-
);
|
|
2299
|
-
let s = length ? reasons.length > 1 ? "since :\n" + reasons.map(renderReason).join("\n") : " " + renderReason(reasons[0]) : "as no adapter specified";
|
|
2300
|
-
throw new AxiosError$1(
|
|
2301
|
-
`There is no suitable adapter to dispatch the request ` + s,
|
|
2302
|
-
"ERR_NOT_SUPPORT"
|
|
2303
|
-
);
|
|
3603
|
+
if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config2)))) {
|
|
3604
|
+
break;
|
|
2304
3605
|
}
|
|
2305
|
-
|
|
2306
|
-
}
|
|
3606
|
+
rejectedReasons[id || "#" + i] = adapter;
|
|
3607
|
+
}
|
|
3608
|
+
if (!adapter) {
|
|
3609
|
+
const reasons = Object.entries(rejectedReasons).map(
|
|
3610
|
+
([id, state]) => `adapter ${id} ` + (state === false ? "is not supported by the environment" : "is not available in the build")
|
|
3611
|
+
);
|
|
3612
|
+
let s = length ? reasons.length > 1 ? "since :\n" + reasons.map(renderReason).join("\n") : " " + renderReason(reasons[0]) : "as no adapter specified";
|
|
3613
|
+
throw new AxiosError$1(
|
|
3614
|
+
`There is no suitable adapter to dispatch the request ` + s,
|
|
3615
|
+
AxiosError$1.ERR_NOT_SUPPORT
|
|
3616
|
+
);
|
|
3617
|
+
}
|
|
3618
|
+
return adapter;
|
|
3619
|
+
}
|
|
3620
|
+
const adapters = {
|
|
3621
|
+
/**
|
|
3622
|
+
* Resolve an adapter from a list of adapter names or functions.
|
|
3623
|
+
* @type {Function}
|
|
3624
|
+
*/
|
|
3625
|
+
getAdapter: getAdapter$1,
|
|
3626
|
+
/**
|
|
3627
|
+
* Exposes all known adapters
|
|
3628
|
+
* @type {Object<string, Function|Object>}
|
|
3629
|
+
*/
|
|
2307
3630
|
adapters: knownAdapters
|
|
2308
3631
|
};
|
|
2309
3632
|
function throwIfCancellationRequested(config2) {
|
|
@@ -2317,39 +3640,44 @@ function throwIfCancellationRequested(config2) {
|
|
|
2317
3640
|
function dispatchRequest(config2) {
|
|
2318
3641
|
throwIfCancellationRequested(config2);
|
|
2319
3642
|
config2.headers = AxiosHeaders$1.from(config2.headers);
|
|
2320
|
-
config2.data = transformData.call(
|
|
2321
|
-
config2,
|
|
2322
|
-
config2.transformRequest
|
|
2323
|
-
);
|
|
3643
|
+
config2.data = transformData.call(config2, config2.transformRequest);
|
|
2324
3644
|
if (["post", "put", "patch"].indexOf(config2.method) !== -1) {
|
|
2325
3645
|
config2.headers.setContentType("application/x-www-form-urlencoded", false);
|
|
2326
3646
|
}
|
|
2327
3647
|
const adapter = adapters.getAdapter(config2.adapter || defaults.adapter, config2);
|
|
2328
|
-
return adapter(config2).then(
|
|
2329
|
-
|
|
2330
|
-
response.data = transformData.call(
|
|
2331
|
-
config2,
|
|
2332
|
-
config2.transformResponse,
|
|
2333
|
-
response
|
|
2334
|
-
);
|
|
2335
|
-
response.headers = AxiosHeaders$1.from(response.headers);
|
|
2336
|
-
return response;
|
|
2337
|
-
}, function onAdapterRejection(reason) {
|
|
2338
|
-
if (!isCancel$1(reason)) {
|
|
3648
|
+
return adapter(config2).then(
|
|
3649
|
+
function onAdapterResolution(response) {
|
|
2339
3650
|
throwIfCancellationRequested(config2);
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
3651
|
+
config2.response = response;
|
|
3652
|
+
try {
|
|
3653
|
+
response.data = transformData.call(config2, config2.transformResponse, response);
|
|
3654
|
+
} finally {
|
|
3655
|
+
delete config2.response;
|
|
3656
|
+
}
|
|
3657
|
+
response.headers = AxiosHeaders$1.from(response.headers);
|
|
3658
|
+
return response;
|
|
3659
|
+
},
|
|
3660
|
+
function onAdapterRejection(reason) {
|
|
3661
|
+
if (!isCancel$1(reason)) {
|
|
3662
|
+
throwIfCancellationRequested(config2);
|
|
3663
|
+
if (reason && reason.response) {
|
|
3664
|
+
config2.response = reason.response;
|
|
3665
|
+
try {
|
|
3666
|
+
reason.response.data = transformData.call(
|
|
3667
|
+
config2,
|
|
3668
|
+
config2.transformResponse,
|
|
3669
|
+
reason.response
|
|
3670
|
+
);
|
|
3671
|
+
} finally {
|
|
3672
|
+
delete config2.response;
|
|
3673
|
+
}
|
|
3674
|
+
reason.response.headers = AxiosHeaders$1.from(reason.response.headers);
|
|
3675
|
+
}
|
|
2347
3676
|
}
|
|
3677
|
+
return Promise.reject(reason);
|
|
2348
3678
|
}
|
|
2349
|
-
|
|
2350
|
-
});
|
|
3679
|
+
);
|
|
2351
3680
|
}
|
|
2352
|
-
const VERSION$1 = "1.12.2";
|
|
2353
3681
|
const validators$1 = {};
|
|
2354
3682
|
["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i) => {
|
|
2355
3683
|
validators$1[type] = function validator2(thing) {
|
|
@@ -2386,20 +3714,23 @@ validators$1.spelling = function spelling(correctSpelling) {
|
|
|
2386
3714
|
return true;
|
|
2387
3715
|
};
|
|
2388
3716
|
};
|
|
2389
|
-
function assertOptions(options,
|
|
2390
|
-
if (typeof options !== "object") {
|
|
3717
|
+
function assertOptions(options, schema2, allowUnknown) {
|
|
3718
|
+
if (typeof options !== "object" || options === null) {
|
|
2391
3719
|
throw new AxiosError$1("options must be an object", AxiosError$1.ERR_BAD_OPTION_VALUE);
|
|
2392
3720
|
}
|
|
2393
3721
|
const keys = Object.keys(options);
|
|
2394
3722
|
let i = keys.length;
|
|
2395
3723
|
while (i-- > 0) {
|
|
2396
3724
|
const opt = keys[i];
|
|
2397
|
-
const validator2 =
|
|
3725
|
+
const validator2 = Object.prototype.hasOwnProperty.call(schema2, opt) ? schema2[opt] : void 0;
|
|
2398
3726
|
if (validator2) {
|
|
2399
3727
|
const value = options[opt];
|
|
2400
3728
|
const result = value === void 0 || validator2(value, opt, options);
|
|
2401
3729
|
if (result !== true) {
|
|
2402
|
-
throw new AxiosError$1(
|
|
3730
|
+
throw new AxiosError$1(
|
|
3731
|
+
"option " + opt + " must be " + result,
|
|
3732
|
+
AxiosError$1.ERR_BAD_OPTION_VALUE
|
|
3733
|
+
);
|
|
2403
3734
|
}
|
|
2404
3735
|
continue;
|
|
2405
3736
|
}
|
|
@@ -2436,12 +3767,23 @@ let Axios$1 = class Axios {
|
|
|
2436
3767
|
if (err instanceof Error) {
|
|
2437
3768
|
let dummy = {};
|
|
2438
3769
|
Error.captureStackTrace ? Error.captureStackTrace(dummy) : dummy = new Error();
|
|
2439
|
-
const stack =
|
|
3770
|
+
const stack = (() => {
|
|
3771
|
+
if (!dummy.stack) {
|
|
3772
|
+
return "";
|
|
3773
|
+
}
|
|
3774
|
+
const firstNewlineIndex = dummy.stack.indexOf("\n");
|
|
3775
|
+
return firstNewlineIndex === -1 ? "" : dummy.stack.slice(firstNewlineIndex + 1);
|
|
3776
|
+
})();
|
|
2440
3777
|
try {
|
|
2441
3778
|
if (!err.stack) {
|
|
2442
3779
|
err.stack = stack;
|
|
2443
|
-
} else if (stack
|
|
2444
|
-
|
|
3780
|
+
} else if (stack) {
|
|
3781
|
+
const firstNewlineIndex = stack.indexOf("\n");
|
|
3782
|
+
const secondNewlineIndex = firstNewlineIndex === -1 ? -1 : stack.indexOf("\n", firstNewlineIndex + 1);
|
|
3783
|
+
const stackWithoutTwoTopLines = secondNewlineIndex === -1 ? "" : stack.slice(secondNewlineIndex + 1);
|
|
3784
|
+
if (!String(err.stack).endsWith(stackWithoutTwoTopLines)) {
|
|
3785
|
+
err.stack += "\n" + stack;
|
|
3786
|
+
}
|
|
2445
3787
|
}
|
|
2446
3788
|
} catch (e) {
|
|
2447
3789
|
}
|
|
@@ -2459,11 +3801,18 @@ let Axios$1 = class Axios {
|
|
|
2459
3801
|
config2 = mergeConfig$1(this.defaults, config2);
|
|
2460
3802
|
const { transitional: transitional2, paramsSerializer, headers } = config2;
|
|
2461
3803
|
if (transitional2 !== void 0) {
|
|
2462
|
-
validator.assertOptions(
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
3804
|
+
validator.assertOptions(
|
|
3805
|
+
transitional2,
|
|
3806
|
+
{
|
|
3807
|
+
silentJSONParsing: validators.transitional(validators.boolean),
|
|
3808
|
+
forcedJSONParsing: validators.transitional(validators.boolean),
|
|
3809
|
+
clarifyTimeoutError: validators.transitional(validators.boolean),
|
|
3810
|
+
legacyInterceptorReqResOrdering: validators.transitional(validators.boolean),
|
|
3811
|
+
advertiseZstdAcceptEncoding: validators.transitional(validators.boolean),
|
|
3812
|
+
validateStatusUndefinedResolves: validators.transitional(validators.boolean)
|
|
3813
|
+
},
|
|
3814
|
+
false
|
|
3815
|
+
);
|
|
2467
3816
|
}
|
|
2468
3817
|
if (paramsSerializer != null) {
|
|
2469
3818
|
if (utils$1.isFunction(paramsSerializer)) {
|
|
@@ -2471,10 +3820,14 @@ let Axios$1 = class Axios {
|
|
|
2471
3820
|
serialize: paramsSerializer
|
|
2472
3821
|
};
|
|
2473
3822
|
} else {
|
|
2474
|
-
validator.assertOptions(
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
3823
|
+
validator.assertOptions(
|
|
3824
|
+
paramsSerializer,
|
|
3825
|
+
{
|
|
3826
|
+
encode: validators.function,
|
|
3827
|
+
serialize: validators.function
|
|
3828
|
+
},
|
|
3829
|
+
true
|
|
3830
|
+
);
|
|
2478
3831
|
}
|
|
2479
3832
|
}
|
|
2480
3833
|
if (config2.allowAbsoluteUrls !== void 0) ;
|
|
@@ -2483,21 +3836,19 @@ let Axios$1 = class Axios {
|
|
|
2483
3836
|
} else {
|
|
2484
3837
|
config2.allowAbsoluteUrls = true;
|
|
2485
3838
|
}
|
|
2486
|
-
validator.assertOptions(
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
headers[config2.method]
|
|
2494
|
-
);
|
|
2495
|
-
headers && utils$1.forEach(
|
|
2496
|
-
["delete", "get", "head", "post", "put", "patch", "common"],
|
|
2497
|
-
(method) => {
|
|
2498
|
-
delete headers[method];
|
|
2499
|
-
}
|
|
3839
|
+
validator.assertOptions(
|
|
3840
|
+
config2,
|
|
3841
|
+
{
|
|
3842
|
+
baseUrl: validators.spelling("baseURL"),
|
|
3843
|
+
withXsrfToken: validators.spelling("withXSRFToken")
|
|
3844
|
+
},
|
|
3845
|
+
true
|
|
2500
3846
|
);
|
|
3847
|
+
config2.method = (config2.method || this.defaults.method || "get").toLowerCase();
|
|
3848
|
+
let contextHeaders = headers && utils$1.merge(headers.common, headers[config2.method]);
|
|
3849
|
+
headers && utils$1.forEach(["delete", "get", "head", "post", "put", "patch", "query", "common"], (method) => {
|
|
3850
|
+
delete headers[method];
|
|
3851
|
+
});
|
|
2501
3852
|
config2.headers = AxiosHeaders$1.concat(contextHeaders, headers);
|
|
2502
3853
|
const requestInterceptorChain = [];
|
|
2503
3854
|
let synchronousRequestInterceptors = true;
|
|
@@ -2506,7 +3857,13 @@ let Axios$1 = class Axios {
|
|
|
2506
3857
|
return;
|
|
2507
3858
|
}
|
|
2508
3859
|
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
|
2509
|
-
|
|
3860
|
+
const transitional3 = config2.transitional || transitionalDefaults;
|
|
3861
|
+
const legacyInterceptorReqResOrdering = transitional3 && transitional3.legacyInterceptorReqResOrdering;
|
|
3862
|
+
if (legacyInterceptorReqResOrdering) {
|
|
3863
|
+
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
|
3864
|
+
} else {
|
|
3865
|
+
requestInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
|
3866
|
+
}
|
|
2510
3867
|
});
|
|
2511
3868
|
const responseInterceptorChain = [];
|
|
2512
3869
|
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
|
@@ -2552,34 +3909,40 @@ let Axios$1 = class Axios {
|
|
|
2552
3909
|
}
|
|
2553
3910
|
getUri(config2) {
|
|
2554
3911
|
config2 = mergeConfig$1(this.defaults, config2);
|
|
2555
|
-
const fullPath = buildFullPath(config2.baseURL, config2.url, config2.allowAbsoluteUrls);
|
|
3912
|
+
const fullPath = buildFullPath(config2.baseURL, config2.url, config2.allowAbsoluteUrls, config2);
|
|
2556
3913
|
return buildURL(fullPath, config2.params, config2.paramsSerializer);
|
|
2557
3914
|
}
|
|
2558
3915
|
};
|
|
2559
3916
|
utils$1.forEach(["delete", "get", "head", "options"], function forEachMethodNoData(method) {
|
|
2560
3917
|
Axios$1.prototype[method] = function(url, config2) {
|
|
2561
|
-
return this.request(
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
3918
|
+
return this.request(
|
|
3919
|
+
mergeConfig$1(config2 || {}, {
|
|
3920
|
+
method,
|
|
3921
|
+
url,
|
|
3922
|
+
data: config2 && utils$1.hasOwnProp(config2, "data") ? config2.data : void 0
|
|
3923
|
+
})
|
|
3924
|
+
);
|
|
2566
3925
|
};
|
|
2567
3926
|
});
|
|
2568
|
-
utils$1.forEach(["post", "put", "patch"], function forEachMethodWithData(method) {
|
|
3927
|
+
utils$1.forEach(["post", "put", "patch", "query"], function forEachMethodWithData(method) {
|
|
2569
3928
|
function generateHTTPMethod(isForm) {
|
|
2570
3929
|
return function httpMethod(url, data, config2) {
|
|
2571
|
-
return this.request(
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
3930
|
+
return this.request(
|
|
3931
|
+
mergeConfig$1(config2 || {}, {
|
|
3932
|
+
method,
|
|
3933
|
+
headers: isForm ? {
|
|
3934
|
+
"Content-Type": "multipart/form-data"
|
|
3935
|
+
} : {},
|
|
3936
|
+
url,
|
|
3937
|
+
data
|
|
3938
|
+
})
|
|
3939
|
+
);
|
|
2579
3940
|
};
|
|
2580
3941
|
}
|
|
2581
3942
|
Axios$1.prototype[method] = generateHTTPMethod();
|
|
2582
|
-
|
|
3943
|
+
if (method !== "query") {
|
|
3944
|
+
Axios$1.prototype[method + "Form"] = generateHTTPMethod(true);
|
|
3945
|
+
}
|
|
2583
3946
|
});
|
|
2584
3947
|
let CancelToken$1 = class CancelToken {
|
|
2585
3948
|
constructor(executor) {
|
|
@@ -2747,7 +4110,13 @@ const HttpStatusCode$1 = {
|
|
|
2747
4110
|
InsufficientStorage: 507,
|
|
2748
4111
|
LoopDetected: 508,
|
|
2749
4112
|
NotExtended: 510,
|
|
2750
|
-
NetworkAuthenticationRequired: 511
|
|
4113
|
+
NetworkAuthenticationRequired: 511,
|
|
4114
|
+
WebServerIsDown: 521,
|
|
4115
|
+
ConnectionTimedOut: 522,
|
|
4116
|
+
OriginIsUnreachable: 523,
|
|
4117
|
+
TimeoutOccurred: 524,
|
|
4118
|
+
SslHandshakeFailed: 525,
|
|
4119
|
+
InvalidSslCertificate: 526
|
|
2751
4120
|
};
|
|
2752
4121
|
Object.entries(HttpStatusCode$1).forEach(([key, value]) => {
|
|
2753
4122
|
HttpStatusCode$1[value] = key;
|
|
@@ -2757,7 +4126,7 @@ function createInstance(defaultConfig) {
|
|
|
2757
4126
|
const instance = bind(Axios$1.prototype.request, context);
|
|
2758
4127
|
utils$1.extend(instance, Axios$1.prototype, context, { allOwnKeys: true });
|
|
2759
4128
|
utils$1.extend(instance, context, null, { allOwnKeys: true });
|
|
2760
|
-
instance.create = function
|
|
4129
|
+
instance.create = function create2(instanceConfig) {
|
|
2761
4130
|
return createInstance(mergeConfig$1(defaultConfig, instanceConfig));
|
|
2762
4131
|
};
|
|
2763
4132
|
return instance;
|
|
@@ -2784,8 +4153,8 @@ axios.HttpStatusCode = HttpStatusCode$1;
|
|
|
2784
4153
|
axios.default = axios;
|
|
2785
4154
|
const {
|
|
2786
4155
|
Axios: Axios2,
|
|
2787
|
-
AxiosError,
|
|
2788
|
-
CanceledError,
|
|
4156
|
+
AxiosError: AxiosError2,
|
|
4157
|
+
CanceledError: CanceledError2,
|
|
2789
4158
|
isCancel,
|
|
2790
4159
|
CancelToken: CancelToken2,
|
|
2791
4160
|
VERSION,
|
|
@@ -2798,27 +4167,46 @@ const {
|
|
|
2798
4167
|
HttpStatusCode,
|
|
2799
4168
|
formToJSON,
|
|
2800
4169
|
getAdapter,
|
|
2801
|
-
mergeConfig
|
|
4170
|
+
mergeConfig,
|
|
4171
|
+
create
|
|
2802
4172
|
} = axios;
|
|
4173
|
+
const VERTEX_LOCATION = "global";
|
|
4174
|
+
const SCOPES = ["https://www.googleapis.com/auth/cloud-platform"];
|
|
4175
|
+
const createGeminiClient = ({ serviceAccount, apiKey, allowVertex = true }, Ctor = genai.GoogleGenAI) => {
|
|
4176
|
+
const parsed = allowVertex && serviceAccount ? parseServiceAccount(serviceAccount) : null;
|
|
4177
|
+
if (parsed && "account" in parsed) {
|
|
4178
|
+
const { projectId, clientEmail, privateKey } = parsed.account;
|
|
4179
|
+
const ai = new Ctor({
|
|
4180
|
+
vertexai: true,
|
|
4181
|
+
project: projectId,
|
|
4182
|
+
location: VERTEX_LOCATION,
|
|
4183
|
+
googleAuthOptions: { credentials: { client_email: clientEmail, private_key: privateKey }, scopes: SCOPES }
|
|
4184
|
+
});
|
|
4185
|
+
return { ai, backend: "vertex" };
|
|
4186
|
+
}
|
|
4187
|
+
if (typeof apiKey === "string" && apiKey) return { ai: new Ctor({ apiKey }), backend: "gemini-api" };
|
|
4188
|
+
throw new Error(
|
|
4189
|
+
allowVertex ? "Configura la cuenta de servicio de Vertex AI o la llave de Gemini en Ajustes del plugin." : "El video necesita la llave de Gemini en Ajustes del plugin."
|
|
4190
|
+
);
|
|
4191
|
+
};
|
|
2803
4192
|
const service = ({ strapi }) => {
|
|
2804
4193
|
return {
|
|
2805
4194
|
// ───────────────────────────────
|
|
2806
4195
|
// 🤖 AI Configuration
|
|
2807
4196
|
// ───────────────────────────────
|
|
4197
|
+
/**
|
|
4198
|
+
* Cliente de Google y su backend (S5.1): con la cuenta de servicio de Ajustes, Vertex AI en `global`; si
|
|
4199
|
+
* no, la llave (`GOOGLE_API_KEY` del entorno gana a la del store, como antes; D10). El video pide
|
|
4200
|
+
* `allowVertex: false` (D7).
|
|
4201
|
+
*/
|
|
4202
|
+
async geminiClient({ allowVertex = true } = {}) {
|
|
4203
|
+
const pluginStore = strapi.store({ type: "plugin", name: "strapi-content-generator-gemini" });
|
|
4204
|
+
const [serviceAccount, storedKey] = await Promise.all([pluginStore.get({ key: VERTEX_KEY }), pluginStore.get({ key: "GOOGLE_GEN_AI" })]);
|
|
4205
|
+
return createGeminiClient({ serviceAccount, apiKey: process.env.GOOGLE_API_KEY || storedKey, allowVertex });
|
|
4206
|
+
},
|
|
4207
|
+
/** Atajo para los usos que solo necesitan el cliente (artículos). */
|
|
2808
4208
|
async geminiConfig() {
|
|
2809
|
-
|
|
2810
|
-
type: "plugin",
|
|
2811
|
-
name: "strapi-content-generator-gemini"
|
|
2812
|
-
});
|
|
2813
|
-
const googleGenAI = await pluginStore.get({ key: "GOOGLE_GEN_AI" });
|
|
2814
|
-
const geminiApiKey = process.env.GOOGLE_API_KEY || googleGenAI;
|
|
2815
|
-
if (!geminiApiKey) {
|
|
2816
|
-
throw new Error(
|
|
2817
|
-
"La variable de entorno GOOGLE_API_KEY o GOOGLE_GEN_AI no está configurada."
|
|
2818
|
-
);
|
|
2819
|
-
}
|
|
2820
|
-
const ai = new genai.GoogleGenAI({ apiKey: geminiApiKey });
|
|
2821
|
-
return ai;
|
|
4209
|
+
return (await this.geminiClient()).ai;
|
|
2822
4210
|
},
|
|
2823
4211
|
async getArticulos(sanitizedQueryParams) {
|
|
2824
4212
|
return await strapi.entityService.findMany("api::articulo.articulo", sanitizedQueryParams);
|
|
@@ -2829,29 +4217,6 @@ const service = ({ strapi }) => {
|
|
|
2829
4217
|
async getUsuarios(sanitizedQueryParams) {
|
|
2830
4218
|
return await strapi.documents("plugin::users-permissions.user").findMany(sanitizedQueryParams);
|
|
2831
4219
|
},
|
|
2832
|
-
async getImagenes() {
|
|
2833
|
-
const existingFolders = await strapi.documents("plugin::upload.folder").findMany({
|
|
2834
|
-
filters: {
|
|
2835
|
-
name: "Generated"
|
|
2836
|
-
}
|
|
2837
|
-
});
|
|
2838
|
-
if (existingFolders) {
|
|
2839
|
-
return await strapi.documents("plugin::upload.file").findMany({
|
|
2840
|
-
filters: {
|
|
2841
|
-
folder: {
|
|
2842
|
-
id: {
|
|
2843
|
-
$eq: existingFolders[0].id
|
|
2844
|
-
}
|
|
2845
|
-
}
|
|
2846
|
-
},
|
|
2847
|
-
sort: ["createdAt:desc"]
|
|
2848
|
-
});
|
|
2849
|
-
}
|
|
2850
|
-
return [];
|
|
2851
|
-
},
|
|
2852
|
-
async eliminarImagen(sanitizedQueryParams) {
|
|
2853
|
-
return await strapi.documents("plugin::upload.file").delete(sanitizedQueryParams);
|
|
2854
|
-
},
|
|
2855
4220
|
// ───────────────────────────────
|
|
2856
4221
|
// 📥 Proxy File Download (bypasses browser CORS)
|
|
2857
4222
|
// ───────────────────────────────
|
|
@@ -2889,27 +4254,7 @@ const service = ({ strapi }) => {
|
|
|
2889
4254
|
// 🏞️ Internal File Upload Helper
|
|
2890
4255
|
// ───────────────────────────────
|
|
2891
4256
|
async _uploadGeneratedFile(file, filename, mimeType, folderName = "Generated") {
|
|
2892
|
-
const
|
|
2893
|
-
filters: { name: folderName }
|
|
2894
|
-
});
|
|
2895
|
-
let folderId;
|
|
2896
|
-
if (!existingFolders || existingFolders.length === 0) {
|
|
2897
|
-
const lastFolder = await strapi.documents("plugin::upload.folder").findMany({
|
|
2898
|
-
sort: { pathId: "desc" },
|
|
2899
|
-
limit: 1
|
|
2900
|
-
});
|
|
2901
|
-
const pathId = Array.isArray(lastFolder) && lastFolder.length > 0 ? lastFolder[0].pathId + 1 : 1;
|
|
2902
|
-
const createdFolder = await strapi.documents("plugin::upload.folder").create({
|
|
2903
|
-
data: {
|
|
2904
|
-
name: folderName,
|
|
2905
|
-
path: `/${folderName.toLowerCase()}`,
|
|
2906
|
-
pathId
|
|
2907
|
-
}
|
|
2908
|
-
});
|
|
2909
|
-
folderId = createdFolder.id;
|
|
2910
|
-
} else {
|
|
2911
|
-
folderId = existingFolders[0].id;
|
|
2912
|
-
}
|
|
4257
|
+
const folderId = await ensureFolder(strapi, folderName);
|
|
2913
4258
|
let fileSize = 0;
|
|
2914
4259
|
if (typeof file === "string") {
|
|
2915
4260
|
const stats = fs__namespace.statSync(file);
|
|
@@ -3144,15 +4489,7 @@ const service = ({ strapi }) => {
|
|
|
3144
4489
|
output_format: "image/png"
|
|
3145
4490
|
};
|
|
3146
4491
|
const promptText = JSON.stringify(promptJson);
|
|
3147
|
-
const generatedBase64Image = await
|
|
3148
|
-
promptText,
|
|
3149
|
-
aspectRatio || "16:9",
|
|
3150
|
-
// Use provided aspectRatio or default
|
|
3151
|
-
imageSize || "1K",
|
|
3152
|
-
// Use provided imageSize or default
|
|
3153
|
-
[]
|
|
3154
|
-
// No reference images for article generation
|
|
3155
|
-
);
|
|
4492
|
+
const generatedBase64Image = await strapi.plugin("strapi-content-generator-gemini").service("image-studio").generateForArticle(promptText, aspectRatio || "16:9", imageSize || "1K");
|
|
3156
4493
|
const buffer = Buffer.from(generatedBase64Image, "base64");
|
|
3157
4494
|
const uploadedFile = await this._uploadGeneratedFile(buffer, `article-${articleId}.png`, "image/png");
|
|
3158
4495
|
const articleModel = await strapi.getModel("api::articulo.articulo");
|
|
@@ -3175,134 +4512,10 @@ const service = ({ strapi }) => {
|
|
|
3175
4512
|
throw new Error("Error al generar la imagen para el artículo.");
|
|
3176
4513
|
}
|
|
3177
4514
|
},
|
|
3178
|
-
// ───────────────────────────────
|
|
3179
|
-
// 🖼️ Internal Image Generation Helper
|
|
3180
|
-
// Imagen 4 cuando no hay imágenes de referencia (mejor calidad y adherencia al prompt)
|
|
3181
|
-
// Gemini 2.5 Flash como fallback cuando se proporcionan imágenes de referencia
|
|
3182
|
-
// ───────────────────────────────
|
|
3183
|
-
async _callGeminiImageGeneration(promptText, aspectRatio, imageSizeLabel, referenceImages) {
|
|
3184
|
-
const ai = await this.geminiConfig();
|
|
3185
|
-
const cleanPrompt = promptText.replace(/\r\n/g, " ").replace(/\n/g, " ").replace(/\s+/g, " ").trim();
|
|
3186
|
-
if (referenceImages.length === 0) {
|
|
3187
|
-
const response = await ai.models.generateImages({
|
|
3188
|
-
model: "imagen-4.0-generate-001",
|
|
3189
|
-
prompt: cleanPrompt,
|
|
3190
|
-
config: {
|
|
3191
|
-
numberOfImages: 1,
|
|
3192
|
-
aspectRatio,
|
|
3193
|
-
outputMimeType: "image/png"
|
|
3194
|
-
}
|
|
3195
|
-
});
|
|
3196
|
-
const imageBytes = response.generatedImages?.[0]?.image?.imageBytes;
|
|
3197
|
-
if (!imageBytes) {
|
|
3198
|
-
throw new Error("Imagen 4 no devolvió imagen. Verifica el prompt o el modelo.");
|
|
3199
|
-
}
|
|
3200
|
-
return imageBytes;
|
|
3201
|
-
}
|
|
3202
|
-
const imageParts = referenceImages.map((img) => ({
|
|
3203
|
-
inlineData: {
|
|
3204
|
-
mimeType: img.mimeType,
|
|
3205
|
-
data: img.buffer.toString("base64")
|
|
3206
|
-
}
|
|
3207
|
-
}));
|
|
3208
|
-
const result = await ai.models.generateContent({
|
|
3209
|
-
model: "gemini-2.5-flash-image",
|
|
3210
|
-
contents: [{ text: cleanPrompt }, ...imageParts],
|
|
3211
|
-
config: {
|
|
3212
|
-
responseModalities: [genai.Modality.IMAGE],
|
|
3213
|
-
imageConfig: { aspectRatio, imageSize: imageSizeLabel }
|
|
3214
|
-
}
|
|
3215
|
-
});
|
|
3216
|
-
const parts = result?.candidates?.[0]?.content?.parts;
|
|
3217
|
-
if (!Array.isArray(parts)) {
|
|
3218
|
-
throw new Error("Respuesta inválida del modelo (parts no encontrado)");
|
|
3219
|
-
}
|
|
3220
|
-
const imagePart = parts.find(
|
|
3221
|
-
(p) => p?.inlineData?.data && typeof p.inlineData.data === "string" && p.inlineData.mimeType?.startsWith("image/")
|
|
3222
|
-
);
|
|
3223
|
-
if (!imagePart) {
|
|
3224
|
-
throw new Error("No se encontró ninguna imagen en la respuesta del modelo");
|
|
3225
|
-
}
|
|
3226
|
-
return imagePart.inlineData.data;
|
|
3227
|
-
},
|
|
3228
|
-
// ───────────────────────────────
|
|
3229
|
-
// 🖼️ Generate Image (Standalone)
|
|
3230
|
-
// ───────────────────────────────
|
|
3231
|
-
async generateImage(ctx) {
|
|
3232
|
-
const { prompt, aspectRatio, imageSize } = ctx.request.body;
|
|
3233
|
-
if (!prompt) {
|
|
3234
|
-
throw new Error("Se requiere 'prompt' para generar el contenido visual.");
|
|
3235
|
-
}
|
|
3236
|
-
const promptJson = {
|
|
3237
|
-
label: `standalone-image-${Date.now()}`,
|
|
3238
|
-
task: "generate_image",
|
|
3239
|
-
canvas: {
|
|
3240
|
-
resolution: imageSize || "1K",
|
|
3241
|
-
aspect_ratio: aspectRatio || "16:9"
|
|
3242
|
-
},
|
|
3243
|
-
style: {
|
|
3244
|
-
type: "architectural software engineering visualization",
|
|
3245
|
-
aesthetic: "high-end technical 3D render / octane style",
|
|
3246
|
-
background: "view of a bright white minimalist architectural gallery, sun-drenched space, white polished floors and tall glass windows",
|
|
3247
|
-
lighting: "intense natural daylight, soft global illumination, clean diffused light with subtle volumetric rays from windows"
|
|
3248
|
-
},
|
|
3249
|
-
concept_brief: prompt,
|
|
3250
|
-
subject: [
|
|
3251
|
-
"apply the concept brief above as the main subject — rendered as a sophisticated 3D holographic or architectural structure floating inside the gallery",
|
|
3252
|
-
"materials: frosted glass, white matte ceramic, polished metal accents",
|
|
3253
|
-
"brand accent colors red #E4002B and teal #00C7B1 on glowing energy filaments, highlights, and data connections",
|
|
3254
|
-
"the structure casts a sharp, clean reflection on the white polished gallery floor",
|
|
3255
|
-
"STRICTLY NO people, NO humans, NO hands, NO chairs",
|
|
3256
|
-
"STRICTLY NO text, NO labels, NO words, NO letters, NO numbers, NO logos",
|
|
3257
|
-
"high-end 3D render, architectural photography style, 4k quality"
|
|
3258
|
-
],
|
|
3259
|
-
camera: {
|
|
3260
|
-
perspective: "three-quarter wide shot, slightly elevated, showing both the subject and the gallery environment",
|
|
3261
|
-
depth_of_field: "main subject in sharp focus, gallery background beautifully blurred"
|
|
3262
|
-
},
|
|
3263
|
-
render: {
|
|
3264
|
-
engine: "Octane or Cinema 4D",
|
|
3265
|
-
effects: "bloom on glowing elements, ray-traced reflections on the white polished floor, subsurface scattering on frosted glass, volumetric light rays from gallery windows",
|
|
3266
|
-
quality: "masterpiece, hyper-detailed"
|
|
3267
|
-
},
|
|
3268
|
-
output_format: "image/png"
|
|
3269
|
-
};
|
|
3270
|
-
const basePrompt = JSON.stringify(promptJson);
|
|
3271
|
-
const files = ctx.request.files ?? {};
|
|
3272
|
-
const referenceImages = Object.entries(files).filter(([key]) => key.startsWith("referenceImages")).map(([, file]) => file);
|
|
3273
|
-
if (referenceImages.length > 5) {
|
|
3274
|
-
throw new Error("Máximo 5 imágenes de referencia permitidas.");
|
|
3275
|
-
}
|
|
3276
|
-
const imageBuffers = referenceImages.map((file) => {
|
|
3277
|
-
const typedFile = file;
|
|
3278
|
-
return {
|
|
3279
|
-
buffer: typedFile.buffer ?? fs__namespace.readFileSync(typedFile.filepath),
|
|
3280
|
-
mimeType: typedFile.mimetype
|
|
3281
|
-
};
|
|
3282
|
-
});
|
|
3283
|
-
try {
|
|
3284
|
-
const generatedBase64Image = await this._callGeminiImageGeneration(
|
|
3285
|
-
basePrompt,
|
|
3286
|
-
aspectRatio || "16:9",
|
|
3287
|
-
imageSize || "1K",
|
|
3288
|
-
imageBuffers
|
|
3289
|
-
);
|
|
3290
|
-
const buffer = Buffer.from(generatedBase64Image, "base64");
|
|
3291
|
-
const filename = `generated-image-${Date.now()}.png`;
|
|
3292
|
-
const uploadedFile = await this._uploadGeneratedFile(buffer, filename, "image/png");
|
|
3293
|
-
return {
|
|
3294
|
-
message: `Imagen generada y subida correctamente.`,
|
|
3295
|
-
file: uploadedFile
|
|
3296
|
-
};
|
|
3297
|
-
} catch (err) {
|
|
3298
|
-
console.error("🚀 ~ generateImage ~ err:", err);
|
|
3299
|
-
throw new Error(`Error al generar la imagen.`);
|
|
3300
|
-
}
|
|
3301
|
-
},
|
|
3302
4515
|
// 🎞️ Internal Veo Video Generation / Extension Helper
|
|
3303
4516
|
async _callVeoVideoGeneration(promptText, aspectRatio, durationSeconds, sceneRefs, previousVideo) {
|
|
3304
|
-
const ai = await this.
|
|
3305
|
-
const
|
|
4517
|
+
const { ai } = await this.geminiClient({ allowVertex: false });
|
|
4518
|
+
const cleanPrompt2 = promptText.replace(/\s+/g, " ").trim();
|
|
3306
4519
|
const referenceImages = sceneRefs.map((img) => ({
|
|
3307
4520
|
image: {
|
|
3308
4521
|
imageBytes: img.buffer.toString("base64"),
|
|
@@ -3319,7 +4532,7 @@ const service = ({ strapi }) => {
|
|
|
3319
4532
|
};
|
|
3320
4533
|
const operationParams = {
|
|
3321
4534
|
model: "veo-3.1-generate-preview",
|
|
3322
|
-
prompt:
|
|
4535
|
+
prompt: cleanPrompt2,
|
|
3323
4536
|
config: config2
|
|
3324
4537
|
};
|
|
3325
4538
|
if (previousVideo) {
|
|
@@ -3371,7 +4584,7 @@ const service = ({ strapi }) => {
|
|
|
3371
4584
|
throw new Error("No se generó ningún video.");
|
|
3372
4585
|
}
|
|
3373
4586
|
const finalVideoPath = `/tmp/video-${Date.now()}.mp4`;
|
|
3374
|
-
const ai = await this.
|
|
4587
|
+
const { ai } = await this.geminiClient({ allowVertex: false });
|
|
3375
4588
|
await ai.files.download({ file: previousVideo, downloadPath: finalVideoPath });
|
|
3376
4589
|
const uploadedFile = await this._uploadGeneratedFile(
|
|
3377
4590
|
finalVideoPath,
|
|
@@ -3551,13 +4764,15 @@ ${hashtags}`,
|
|
|
3551
4764
|
};
|
|
3552
4765
|
};
|
|
3553
4766
|
const services = {
|
|
3554
|
-
service
|
|
4767
|
+
service,
|
|
4768
|
+
"image-studio": imageStudio$1,
|
|
4769
|
+
templates: templates$1
|
|
3555
4770
|
};
|
|
3556
4771
|
const index = {
|
|
3557
4772
|
register,
|
|
3558
4773
|
bootstrap,
|
|
3559
4774
|
destroy,
|
|
3560
|
-
config: config$
|
|
4775
|
+
config: config$2,
|
|
3561
4776
|
controllers,
|
|
3562
4777
|
routes,
|
|
3563
4778
|
services,
|