@interware/content-generator 0.4.4 → 0.5.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-BQr5_g5u.mjs → App-DPVBu7QB.mjs} +37 -726
- package/dist/_chunks/{App-CfwvfmvL.js → App-DVTFrZvf.js} +31 -720
- package/dist/_chunks/ImageStudioTabs-B2UbKYq7.js +5299 -0
- package/dist/_chunks/ImageStudioTabs-mlNL6aQ2.mjs +5298 -0
- package/dist/_chunks/Settings-DziRY70a.js +155 -0
- package/dist/_chunks/Settings-RrBQdijj.mjs +155 -0
- package/dist/_chunks/StudioApp-AUyPNhh2.mjs +17 -0
- package/dist/_chunks/StudioApp-Cswkzh7F.js +17 -0
- package/dist/_chunks/{getTranslation-DNhP1INv.js → getTranslation-D88uLXGd.js} +1 -1
- package/dist/_chunks/{getTranslation-B9ND5RaH.mjs → getTranslation-DfxaP_TC.mjs} +1 -1
- package/dist/_chunks/{index-Dyq8dxMX.mjs → index-CqDdi211.mjs} +25 -7
- package/dist/_chunks/{index-DGPqyrzz.js → index-Ddp0Qvqo.js} +24 -6
- 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 +8 -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/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 +13 -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 +2408 -1261
- package/dist/server/index.mjs +2415 -1267
- 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 +2 -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 +128 -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 +38 -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 +229 -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 +62 -0
- package/dist/server/src/services/index.d.ts +27 -57
- package/dist/server/src/services/service.d.ts +0 -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/secrets.d.ts +9 -0
- package/package.json +22 -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,719 @@ 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 CREDENTIALS = {
|
|
184
|
+
googleGenAI: "GOOGLE_GEN_AI",
|
|
185
|
+
linkedInAccessToken: "LINKEDIN_ACCESS_TOKEN",
|
|
186
|
+
linkedInOrganizationId: "LINKEDIN_ORGANIZATION_ID",
|
|
187
|
+
facebookClientToken: "FACEBOOK_CLIENT_TOKEN",
|
|
188
|
+
facebookPageId: "FACEBOOK_PAGE_ID"
|
|
189
|
+
};
|
|
190
|
+
const FIELDS$1 = Object.keys(CREDENTIALS);
|
|
191
|
+
const config$1 = ({ strapi }) => {
|
|
192
|
+
const pluginStore = () => strapi.store({
|
|
193
|
+
type: "plugin",
|
|
194
|
+
name: "strapi-content-generator-gemini"
|
|
195
|
+
});
|
|
166
196
|
return {
|
|
197
|
+
/** Devuelve si cada credencial está guardada y sus últimos 4 caracteres, nunca el valor. */
|
|
167
198
|
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 };
|
|
199
|
+
const store = pluginStore();
|
|
200
|
+
const entries = await Promise.all(
|
|
201
|
+
FIELDS$1.map(async (field) => [field, maskSecret(await store.get({ key: CREDENTIALS[field] }))])
|
|
202
|
+
);
|
|
203
|
+
ctx.body = Object.fromEntries(entries);
|
|
178
204
|
},
|
|
205
|
+
/** Escribe solo las credenciales conocidas que llegan como texto no vacío. */
|
|
179
206
|
async set(ctx) {
|
|
180
|
-
const
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
await pluginStore.set({ key: "FACEBOOK_CLIENT_TOKEN", value: facebookClientToken });
|
|
189
|
-
await pluginStore.set({ key: "FACEBOOK_PAGE_ID", value: facebookPageId });
|
|
207
|
+
const body = ctx.request.body ?? {};
|
|
208
|
+
const store = pluginStore();
|
|
209
|
+
for (const field of FIELDS$1) {
|
|
210
|
+
const value = body[field];
|
|
211
|
+
if (typeof value === "string" && value.length > 0) {
|
|
212
|
+
await store.set({ key: CREDENTIALS[field], value });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
190
215
|
ctx.body = { ok: true };
|
|
191
216
|
}
|
|
192
217
|
};
|
|
193
218
|
};
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
219
|
+
const PEOPLE_CLAUSE = "STRICTLY NO people, NO humans, NO faces, NO hands.";
|
|
220
|
+
const HARM_CATEGORIES = [
|
|
221
|
+
genai.HarmCategory.HARM_CATEGORY_HARASSMENT,
|
|
222
|
+
genai.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
|
|
223
|
+
genai.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
|
|
224
|
+
genai.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT
|
|
225
|
+
];
|
|
226
|
+
const safetySettings = (safety) => HARM_CATEGORIES.map((category) => ({
|
|
227
|
+
category,
|
|
228
|
+
threshold: safety ? genai.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE : genai.HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
229
|
+
}));
|
|
230
|
+
const PEOPLE = {
|
|
231
|
+
none: "ALLOW_NONE",
|
|
232
|
+
adults: genai.PersonGeneration.ALLOW_ADULT
|
|
197
233
|
};
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
{
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
{
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
234
|
+
const imageConfig = ({ aspectRatio, imageSize, allowPeople }, backend = "gemini-api") => ({
|
|
235
|
+
...aspectRatio ? { aspectRatio } : {},
|
|
236
|
+
...imageSize ? { imageSize } : {},
|
|
237
|
+
...backend === "vertex" ? { personGeneration: allowPeople ? PEOPLE.adults : PEOPLE.none } : {}
|
|
238
|
+
});
|
|
239
|
+
const promptPart = (text2, allowPeople, backend = "gemini-api") => ({
|
|
240
|
+
text: backend === "gemini-api" && !allowPeople ? `${text2} ${PEOPLE_CLAUSE}` : text2
|
|
241
|
+
});
|
|
242
|
+
const searchTool = () => ({ googleSearch: { searchTypes: { webSearch: {}, imageSearch: {} } } });
|
|
243
|
+
const generateConfig = ({ aspectRatio, imageSize, allowPeople, safety, grounding }, backend = "gemini-api") => ({
|
|
244
|
+
// Con búsqueda el modelo responde texto e imagen.
|
|
245
|
+
responseModalities: grounding ? [genai.Modality.TEXT, genai.Modality.IMAGE] : [genai.Modality.IMAGE],
|
|
246
|
+
imageConfig: imageConfig({ aspectRatio, imageSize, allowPeople }, backend),
|
|
247
|
+
safetySettings: safetySettings(safety),
|
|
248
|
+
...grounding ? { tools: [searchTool()] } : {}
|
|
249
|
+
});
|
|
250
|
+
const editConfig = ({ safety, allowPeople, aspectRatio }, backend = "gemini-api") => ({
|
|
251
|
+
responseModalities: [genai.Modality.IMAGE],
|
|
252
|
+
imageConfig: imageConfig({ aspectRatio, allowPeople }, backend),
|
|
253
|
+
safetySettings: safetySettings(safety)
|
|
254
|
+
});
|
|
255
|
+
const inlinePart = (bytes, mimeType) => ({ inlineData: { mimeType, data: bytes.toString("base64") } });
|
|
256
|
+
const RATIOS = ["1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"];
|
|
257
|
+
const FLASH_RATIOS = [...RATIOS, "1:4", "4:1", "1:8", "8:1"];
|
|
258
|
+
const FLASH = { maxReferences: 6, sizes: ["512", "1K", "2K", "4K"], aspectRatios: FLASH_RATIOS, canEdit: true, grounding: true };
|
|
259
|
+
const FLASH_LITE = { maxReferences: 6, sizes: ["512", "1K"], aspectRatios: RATIOS, canEdit: true, grounding: false };
|
|
260
|
+
const PRO = { maxReferences: 6, sizes: ["1K", "2K", "4K"], aspectRatios: RATIOS, canEdit: true, grounding: false };
|
|
261
|
+
const IMAGE_MODELS = [
|
|
262
|
+
{ id: "gemini-3.1-flash-image", label: "Nano Banana 2", ...FLASH },
|
|
263
|
+
{ id: "gemini-3.1-flash-image-preview", label: "Nano Banana 2 (preview)", ...FLASH },
|
|
264
|
+
{ id: "gemini-3.1-flash-lite-image", label: "Nano Banana 2 Lite", ...FLASH_LITE },
|
|
265
|
+
{ id: "gemini-3.1-flash-lite-image-preview", label: "Nano Banana 2 Lite (preview)", ...FLASH_LITE },
|
|
266
|
+
{ id: "gemini-3-pro-image", label: "Nano Banana Pro", ...PRO },
|
|
267
|
+
{ id: "gemini-3-pro-image-preview", label: "Nano Banana Pro (preview)", ...PRO },
|
|
268
|
+
{ id: "gemini-2.5-flash-image", label: "Nano Banana (legado)", maxReferences: 3, sizes: [], aspectRatios: RATIOS, canEdit: true, grounding: false }
|
|
269
|
+
];
|
|
270
|
+
const findModel = (id) => IMAGE_MODELS.find((m) => m.id === id);
|
|
271
|
+
const availableModels = (listed) => {
|
|
272
|
+
if (!listed) return { models: IMAGE_MODELS, verified: false };
|
|
273
|
+
const ids = new Set(listed.map((n) => n.replace(/^models\//, "")));
|
|
274
|
+
const models = IMAGE_MODELS.filter((m) => ids.has(m.id) && !(m.id.endsWith("-preview") && ids.has(m.id.replace(/-preview$/, ""))));
|
|
275
|
+
return models.length ? { models, verified: true } : { models: IMAGE_MODELS, verified: false };
|
|
276
|
+
};
|
|
277
|
+
const editModelFor = (id) => {
|
|
278
|
+
const chosen = findModel(id);
|
|
279
|
+
if (chosen?.canEdit) return chosen;
|
|
280
|
+
return IMAGE_MODELS.find((m) => m.canEdit);
|
|
281
|
+
};
|
|
282
|
+
const PROMPT_MAX = 2e3;
|
|
283
|
+
const CONTROL = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g;
|
|
284
|
+
const INVISIBLE = /[----]/g;
|
|
285
|
+
const TAG = /<\/?[a-z][^>]*>/gi;
|
|
286
|
+
const sanitizePrompt = (text2) => text2.normalize("NFC").replace(CONTROL, "").replace(INVISIBLE, "").replace(TAG, "").replace(/\s+/g, " ").trim();
|
|
287
|
+
const PROMPT_LABELS = { label: "El prompt", empty: "Escribe un prompt." };
|
|
288
|
+
const INSTRUCTION_LABELS = { label: "La instrucción", empty: "Describe el cambio que quieres." };
|
|
289
|
+
const checkPrompt = (text2, { label, empty } = PROMPT_LABELS) => {
|
|
290
|
+
const clean2 = sanitizePrompt(text2);
|
|
291
|
+
if (!clean2) return { ok: false, error: empty };
|
|
292
|
+
if ([...clean2].length > PROMPT_MAX) return { ok: false, error: `${label} puede tener hasta ${PROMPT_MAX} caracteres.` };
|
|
293
|
+
return { ok: true, text: clean2 };
|
|
294
|
+
};
|
|
295
|
+
const cleanPrompt = sanitizePrompt;
|
|
296
|
+
const EXPAND_INSTRUCTION = (concept) => [
|
|
297
|
+
"Eres experto en prompts para generadores de imágenes con IA.",
|
|
298
|
+
"Expande y mejora este concepto con sujeto, composición, estilo, iluminación y color.",
|
|
299
|
+
"Responde solo con el prompt mejorado, en español, sin explicaciones, comillas ni viñetas.",
|
|
300
|
+
`Concepto: ${concept}`
|
|
301
|
+
].join("\n");
|
|
302
|
+
class BlockedError extends Error {
|
|
303
|
+
}
|
|
304
|
+
const sourceOf = (chunk) => {
|
|
305
|
+
if (chunk.web?.uri) return { title: chunk.web.title || new URL(chunk.web.uri).hostname, uri: chunk.web.uri };
|
|
306
|
+
const img = chunk.image;
|
|
307
|
+
if (img?.sourceUri) return { title: img.title || img.domain || new URL(img.sourceUri).hostname, uri: img.sourceUri };
|
|
308
|
+
return null;
|
|
309
|
+
};
|
|
310
|
+
const groundingFrom = (res) => {
|
|
311
|
+
const meta = res.candidates?.[0]?.groundingMetadata;
|
|
312
|
+
const sources = (meta?.groundingChunks ?? []).map(sourceOf).filter((src) => src !== null).filter((src, i, all3) => all3.findIndex((o) => o.title === src.title) === i);
|
|
313
|
+
const queries = [.../* @__PURE__ */ new Set([...meta?.webSearchQueries ?? [], ...meta?.imageSearchQueries ?? []])];
|
|
314
|
+
const suggestions = meta?.searchEntryPoint?.renderedContent;
|
|
315
|
+
if (!sources.length && !queries.length && !suggestions) return void 0;
|
|
316
|
+
return { ...suggestions ? { suggestions } : {}, queries, sources };
|
|
317
|
+
};
|
|
318
|
+
const EXPAND_MODEL = "gemini-2.5-flash";
|
|
319
|
+
const BLOCK_REASONS = {
|
|
320
|
+
SAFETY: "El modelo bloqueó la solicitud por seguridad. Ajusta el prompt o la imagen.",
|
|
321
|
+
PROHIBITED_CONTENT: "El modelo bloqueó la solicitud por contenido no permitido.",
|
|
322
|
+
IMAGE_SAFETY: "El modelo bloqueó la imagen resultante por seguridad."
|
|
323
|
+
};
|
|
324
|
+
const imageFrom = (res, model) => {
|
|
325
|
+
const parts = res.candidates?.[0]?.content?.parts ?? [];
|
|
326
|
+
const part = parts.find((p) => p.inlineData?.data && (p.inlineData.mimeType ?? "").startsWith("image/"));
|
|
327
|
+
if (part?.inlineData?.data) return { image: part.inlineData.data, mimeType: part.inlineData.mimeType ?? "image/png", model };
|
|
328
|
+
const reason = res.promptFeedback?.blockReason ?? res.candidates?.[0]?.finishReason;
|
|
329
|
+
throw new BlockedError(BLOCK_REASONS[String(reason)] ?? "El modelo no devolvió una imagen. Intenta con otro prompt.");
|
|
330
|
+
};
|
|
331
|
+
const inline = async (file, read) => inlinePart(await read(file.filepath), file.mimetype ?? "image/png");
|
|
332
|
+
const userTurn = (parts) => [{ role: "user", parts }];
|
|
333
|
+
const createImageStudio = (getModels, read = (p) => fs.promises.readFile(p), backend = "gemini-api") => ({
|
|
334
|
+
async models() {
|
|
335
|
+
try {
|
|
336
|
+
const api = await getModels();
|
|
337
|
+
const names = [];
|
|
338
|
+
for await (const m of await api.list({ config: { pageSize: 100 } })) if (m.name) names.push(m.name);
|
|
339
|
+
return availableModels(names);
|
|
340
|
+
} catch {
|
|
341
|
+
return availableModels(null);
|
|
217
342
|
}
|
|
218
343
|
},
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
344
|
+
/**
|
|
345
|
+
* Imagen para un artículo (S4.12): antes usaba Imagen 4, que Google apagó. Usa el primer modelo
|
|
346
|
+
* disponible del catálogo y ajusta proporción y tamaño a lo que admite. Devuelve base64.
|
|
347
|
+
*/
|
|
348
|
+
async generateForArticle(prompt, aspectRatio, imageSize) {
|
|
349
|
+
const [model] = (await this.models()).models;
|
|
350
|
+
const { image } = await this.generate({
|
|
351
|
+
prompt,
|
|
352
|
+
model,
|
|
353
|
+
aspectRatio: model.aspectRatios.includes(aspectRatio) ? aspectRatio : "16:9",
|
|
354
|
+
imageSize: model.sizes.includes(imageSize) ? imageSize : void 0,
|
|
355
|
+
safety: true,
|
|
356
|
+
// El estilo de marca de los artículos no lleva personas (su JSON ya lo pide); ahora también el parámetro.
|
|
357
|
+
allowPeople: false,
|
|
358
|
+
grounding: false,
|
|
359
|
+
references: []
|
|
360
|
+
});
|
|
361
|
+
return image;
|
|
227
362
|
},
|
|
228
|
-
{
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
363
|
+
async generate(input) {
|
|
364
|
+
const api = await getModels();
|
|
365
|
+
const text2 = cleanPrompt(input.prompt);
|
|
366
|
+
const { model } = input;
|
|
367
|
+
const refs = await Promise.all(input.references.map((f) => inline(f, read)));
|
|
368
|
+
const request = {
|
|
369
|
+
model: model.id,
|
|
370
|
+
contents: userTurn([promptPart(text2, input.allowPeople, backend), ...refs]),
|
|
371
|
+
config: generateConfig(input, backend)
|
|
372
|
+
};
|
|
373
|
+
const res = await api.generateContent(request);
|
|
374
|
+
const image = imageFrom(res, model.id);
|
|
375
|
+
const grounding = input.grounding ? groundingFrom(res) : void 0;
|
|
376
|
+
return grounding ? { ...image, grounding } : image;
|
|
236
377
|
},
|
|
237
|
-
{
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
378
|
+
async edit(input) {
|
|
379
|
+
const api = await getModels();
|
|
380
|
+
const parts = [
|
|
381
|
+
await inline(input.image, read),
|
|
382
|
+
...await Promise.all(input.references.map((f) => inline(f, read))),
|
|
383
|
+
promptPart(input.instruction, input.allowPeople, backend)
|
|
384
|
+
];
|
|
385
|
+
const request = { model: input.model.id, contents: userTurn(parts), config: editConfig(input, backend) };
|
|
386
|
+
const res = await api.generateContent(request);
|
|
387
|
+
return imageFrom(res, input.model.id);
|
|
245
388
|
},
|
|
246
|
-
{
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
389
|
+
async expand(prompt) {
|
|
390
|
+
const api = await getModels();
|
|
391
|
+
const res = await api.generateContent({ model: EXPAND_MODEL, contents: EXPAND_INSTRUCTION(cleanPrompt(prompt)) });
|
|
392
|
+
const text2 = (res.text ?? "").trim().replace(/^["'«“]+|["'»”]+$/g, "").trim();
|
|
393
|
+
if (!text2) throw new BlockedError("No se pudo expandir la idea. Intenta de nuevo.");
|
|
394
|
+
return text2;
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
const imageStudio$1 = ({ strapi }) => createImageStudio(async () => (await strapi.plugin("strapi-content-generator-gemini").service("service").geminiConfig()).models);
|
|
398
|
+
class InputError extends Error {
|
|
399
|
+
}
|
|
400
|
+
const ALLOWED = ["image/png", "image/jpeg", "image/webp"];
|
|
401
|
+
const MAX_BYTES = 10 * 1024 * 1024;
|
|
402
|
+
const str = (v) => typeof v === "string" ? v : "";
|
|
403
|
+
const bool = (v) => v === true || v === "true";
|
|
404
|
+
const list = (v) => v ? Array.isArray(v) ? v : [v] : [];
|
|
405
|
+
const clean = (text2, labels) => {
|
|
406
|
+
const r = checkPrompt(text2, labels);
|
|
407
|
+
if ("error" in r) throw new InputError(r.error);
|
|
408
|
+
return r.text;
|
|
409
|
+
};
|
|
410
|
+
const checkImage = (f) => {
|
|
411
|
+
if (!ALLOWED.includes(f.mimetype ?? "")) throw new InputError("Las imágenes deben ser PNG, JPG o WEBP.");
|
|
412
|
+
if (f.size > MAX_BYTES) throw new InputError("Cada imagen puede pesar hasta 10 MB.");
|
|
413
|
+
return f;
|
|
414
|
+
};
|
|
415
|
+
const parseGenerateInput = (fields, files) => {
|
|
416
|
+
const prompt = clean(str(fields.prompt));
|
|
417
|
+
const model = findModel(str(fields.model));
|
|
418
|
+
if (!model) throw new InputError("Modelo no disponible.");
|
|
419
|
+
const aspectRatio = str(fields.aspectRatio) || "1:1";
|
|
420
|
+
if (!model.aspectRatios.includes(aspectRatio)) throw new InputError(`Proporción no disponible para ${model.label}.`);
|
|
421
|
+
const references = list(files.references).map(checkImage);
|
|
422
|
+
if (references.length && model.maxReferences === 0) throw new InputError(`${model.label} no acepta imágenes de referencia.`);
|
|
423
|
+
if (references.length > model.maxReferences) throw new InputError(`Máximo ${model.maxReferences} imágenes de referencia con ${model.label}.`);
|
|
424
|
+
const size2 = str(fields.imageSize);
|
|
425
|
+
return {
|
|
426
|
+
prompt,
|
|
427
|
+
model,
|
|
428
|
+
aspectRatio,
|
|
429
|
+
imageSize: model.sizes.includes(size2) ? size2 : void 0,
|
|
430
|
+
safety: fields.safety === void 0 ? true : bool(fields.safety),
|
|
431
|
+
allowPeople: bool(fields.allowPeople),
|
|
432
|
+
grounding: model.grounding && bool(fields.grounding),
|
|
433
|
+
references
|
|
434
|
+
};
|
|
435
|
+
};
|
|
436
|
+
const parseEditInput = (fields, files) => {
|
|
437
|
+
const instruction = clean(str(fields.instruction), INSTRUCTION_LABELS);
|
|
438
|
+
const [image] = list(files.image);
|
|
439
|
+
if (!image) throw new InputError("Falta la imagen a editar.");
|
|
440
|
+
const model = editModelFor(str(fields.model) || void 0);
|
|
441
|
+
const max = Math.max(0, model.maxReferences - 1);
|
|
442
|
+
const references = list(files.references).map(checkImage);
|
|
443
|
+
if (references.length > max) throw new InputError(`Máximo ${max} elementos para el cambio con ${model.label}.`);
|
|
444
|
+
return {
|
|
445
|
+
instruction,
|
|
446
|
+
model,
|
|
447
|
+
image: checkImage(image),
|
|
448
|
+
references,
|
|
449
|
+
// Sin los campos (clientes anteriores a S4.13): con seguridad y sin excluir personas, como antes.
|
|
450
|
+
safety: fields.safety === void 0 ? true : bool(fields.safety),
|
|
451
|
+
allowPeople: fields.allowPeople === void 0 ? true : bool(fields.allowPeople),
|
|
452
|
+
aspectRatio: model.aspectRatios.includes(str(fields.aspectRatio)) ? str(fields.aspectRatio) : void 0
|
|
453
|
+
};
|
|
454
|
+
};
|
|
455
|
+
const fail$2 = (ctx, status, name2, message) => {
|
|
456
|
+
ctx.status = status;
|
|
457
|
+
ctx.body = { data: null, error: { status, name: name2, message } };
|
|
458
|
+
};
|
|
459
|
+
const imageStudio = ({ strapi }) => {
|
|
460
|
+
const studio = () => strapi.plugin("strapi-content-generator-gemini").service("image-studio");
|
|
461
|
+
const run = async (ctx, work) => {
|
|
462
|
+
try {
|
|
463
|
+
ctx.body = await work();
|
|
464
|
+
} catch (err) {
|
|
465
|
+
if (err instanceof InputError) return fail$2(ctx, 400, "BadRequestError", err.message);
|
|
466
|
+
if (err instanceof BlockedError) return fail$2(ctx, 422, "UnprocessableEntityError", err.message);
|
|
467
|
+
strapi.log.error(`[image-studio] ${err instanceof Error ? err.message : String(err)}`);
|
|
468
|
+
return fail$2(ctx, 502, "BadGatewayError", "El servicio de imágenes no respondió. Intenta de nuevo en un momento.");
|
|
253
469
|
}
|
|
254
|
-
}
|
|
470
|
+
};
|
|
471
|
+
return {
|
|
472
|
+
models: (ctx) => run(ctx, () => studio().models()),
|
|
473
|
+
generate: (ctx) => run(ctx, () => studio().generate(parseGenerateInput(ctx.request.body ?? {}, ctx.request.files ?? {}))),
|
|
474
|
+
edit: (ctx) => run(ctx, () => studio().edit(parseEditInput(ctx.request.body ?? {}, ctx.request.files ?? {}))),
|
|
475
|
+
expand: (ctx) => run(ctx, async () => {
|
|
476
|
+
const raw = typeof ctx.request.body?.prompt === "string" ? ctx.request.body.prompt : "";
|
|
477
|
+
const prompt = clean(raw, { label: "La idea", empty: "Escribe una idea para expandir." });
|
|
478
|
+
return { prompt: await studio().expand(prompt) };
|
|
479
|
+
})
|
|
480
|
+
};
|
|
481
|
+
};
|
|
482
|
+
const NAVY = "#1F2A44";
|
|
483
|
+
const RED = "#E4002B";
|
|
484
|
+
const TEAL = "#00C7B1";
|
|
485
|
+
const GREY = "#5B6473";
|
|
486
|
+
const PAPER = "#EEF1F5";
|
|
487
|
+
const WHITE = "#FFFFFF";
|
|
488
|
+
const WHITE_75 = "rgba(255,255,255,0.75)";
|
|
489
|
+
const WHITE_60 = "rgba(255,255,255,0.6)";
|
|
490
|
+
const WHITE_20 = "rgba(255,255,255,0.2)";
|
|
491
|
+
const BASE_TEMPLATES = [
|
|
255
492
|
{
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
493
|
+
id: "cuadrado_01",
|
|
494
|
+
name: "Cuadrado 01",
|
|
495
|
+
category: "Redes sociales",
|
|
496
|
+
tag: "1:1",
|
|
497
|
+
width: 1080,
|
|
498
|
+
height: 1080,
|
|
499
|
+
background: PAPER,
|
|
500
|
+
safeMargin: 80,
|
|
501
|
+
gridUnit: 60,
|
|
502
|
+
layers: [
|
|
503
|
+
{ id: "logo", type: "logo", label: "Logo", x: 80, y: 80, color: NAVY, logoScale: 1.1 },
|
|
504
|
+
{ 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" },
|
|
505
|
+
{ id: "divider", type: "rect", label: "Divisor", x: 80, y: 530, w: 420, h: 3, color: RED },
|
|
506
|
+
{ 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 }
|
|
507
|
+
]
|
|
263
508
|
},
|
|
264
509
|
{
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
510
|
+
id: "cuadrado_dark",
|
|
511
|
+
name: "Cuadrado Dark",
|
|
512
|
+
category: "Redes sociales",
|
|
513
|
+
tag: "1:1",
|
|
514
|
+
width: 1080,
|
|
515
|
+
height: 1080,
|
|
516
|
+
background: NAVY,
|
|
517
|
+
safeMargin: 80,
|
|
518
|
+
gridUnit: 60,
|
|
519
|
+
layers: [
|
|
520
|
+
{ id: "accent_top", type: "rect", label: "Acento superior", x: 0, y: 0, w: 1080, h: 6, color: RED },
|
|
521
|
+
{ id: "watermark", type: "logo", label: "Marca de agua", x: 600, y: 700, color: WHITE, logoScale: 2.6, opacity: 0.1 },
|
|
522
|
+
{ id: "logo", type: "logo", label: "Logo", x: 80, y: 86, color: WHITE, logoScale: 1.1 },
|
|
523
|
+
{ 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" },
|
|
524
|
+
{ id: "divider", type: "rect", label: "Divisor", x: 80, y: 560, w: 360, h: 3, color: TEAL },
|
|
525
|
+
{ 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 }
|
|
526
|
+
]
|
|
272
527
|
},
|
|
273
528
|
{
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
529
|
+
id: "horizontal_01",
|
|
530
|
+
name: "Horizontal 01",
|
|
531
|
+
category: "Web / Blog",
|
|
532
|
+
tag: "16:9",
|
|
533
|
+
width: 1920,
|
|
534
|
+
height: 1080,
|
|
535
|
+
background: PAPER,
|
|
536
|
+
safeMargin: 100,
|
|
537
|
+
gridUnit: 80,
|
|
538
|
+
layers: [
|
|
539
|
+
{ id: "right_panel", type: "rect", label: "Panel derecho", x: 1056, y: 0, w: 864, h: 1080, color: NAVY },
|
|
540
|
+
{ id: "watermark", type: "logo", label: "Marca de agua", x: 1100, y: 200, color: WHITE, logoScale: 8, opacity: 0.08 },
|
|
541
|
+
{ id: "logo", type: "logo", label: "Logo", x: 100, y: 100, color: NAVY, logoScale: 1.3 },
|
|
542
|
+
{ 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" },
|
|
543
|
+
{ 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" },
|
|
544
|
+
{ id: "divider", type: "rect", label: "Divisor", x: 100, y: 880, w: 300, h: 4, color: NAVY },
|
|
545
|
+
{ id: "url", type: "text", label: "URL", x: 100, y: 990, w: 800, content: "interware.com.mx", fontSize: 22, fontWeight: 500, color: GREY },
|
|
546
|
+
{ id: "logo_right", type: "logo", label: "Logo derecho", x: 1700, y: 990, color: WHITE_60, logoScale: 1.5 }
|
|
547
|
+
]
|
|
281
548
|
},
|
|
282
549
|
{
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
550
|
+
id: "story_01",
|
|
551
|
+
name: "Story / Reels",
|
|
552
|
+
category: "Redes sociales",
|
|
553
|
+
tag: "9:16",
|
|
554
|
+
width: 1080,
|
|
555
|
+
height: 1920,
|
|
556
|
+
background: NAVY,
|
|
557
|
+
safeMargin: 80,
|
|
558
|
+
gridUnit: 80,
|
|
559
|
+
layers: [
|
|
560
|
+
{ id: "watermark", type: "logo", label: "Marca de agua", x: 700, y: -40, color: WHITE, logoScale: 7, opacity: 0.06, rotate: -15 },
|
|
561
|
+
{ id: "accent", type: "rect", label: "Acento superior", x: 0, y: 0, w: 1080, h: 8, color: TEAL },
|
|
562
|
+
{ id: "logo", type: "logo", label: "Logo", x: 80, y: 60, color: WHITE, logoScale: 1.1 },
|
|
563
|
+
{ id: "line", type: "rect", label: "Línea", x: 80, y: 672, w: 60, h: 5, color: TEAL },
|
|
564
|
+
{ 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" },
|
|
565
|
+
{ 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 }
|
|
566
|
+
]
|
|
290
567
|
},
|
|
291
568
|
{
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
569
|
+
id: "blog_hero",
|
|
570
|
+
name: "Blog Hero",
|
|
571
|
+
category: "Web / Blog",
|
|
572
|
+
tag: "~2:1",
|
|
573
|
+
width: 1200,
|
|
574
|
+
height: 630,
|
|
575
|
+
background: PAPER,
|
|
576
|
+
safeMargin: 72,
|
|
577
|
+
gridUnit: 60,
|
|
578
|
+
layers: [
|
|
579
|
+
{ id: "strip", type: "rect", label: "Franja izquierda", x: 0, y: 0, w: 8, h: 630, color: RED },
|
|
580
|
+
{ id: "logo", type: "logo", label: "Logo", x: 80, y: 72, color: NAVY, logoScale: 1 },
|
|
581
|
+
{ 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" },
|
|
582
|
+
{ 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" },
|
|
583
|
+
{ id: "divider", type: "rect", label: "Divisor", x: 80, y: 475, w: 200, h: 3, color: RED },
|
|
584
|
+
{ id: "autor", type: "text", label: "Autor", x: 80, y: 500, w: 800, content: "Por el equipo de InterWare", fontSize: 24, fontWeight: 600, color: GREY }
|
|
585
|
+
]
|
|
299
586
|
},
|
|
300
587
|
{
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
588
|
+
id: "linkedin_banner",
|
|
589
|
+
name: "LinkedIn Banner",
|
|
590
|
+
category: "LinkedIn",
|
|
591
|
+
tag: "4:1",
|
|
592
|
+
width: 1584,
|
|
593
|
+
height: 396,
|
|
594
|
+
background: NAVY,
|
|
595
|
+
safeMargin: 60,
|
|
596
|
+
gridUnit: 60,
|
|
597
|
+
layers: [
|
|
598
|
+
{ id: "watermark", type: "logo", label: "Marca de agua", x: 1100, y: -40, color: WHITE, logoScale: 9, opacity: 0.05 },
|
|
599
|
+
{ id: "strip", type: "rect", label: "Franja", x: 0, y: 0, w: 6, h: 396, color: TEAL, gradient: `linear-gradient(to bottom, ${TEAL}, ${NAVY})` },
|
|
600
|
+
{ id: "logo", type: "logo", label: "Logo", x: 60, y: 150, color: WHITE, logoScale: 1.4 },
|
|
601
|
+
{ id: "vdivider", type: "rect", label: "Divisor vertical", x: 320, y: 158, w: 2, h: 80, color: WHITE_20 },
|
|
602
|
+
{ 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" },
|
|
603
|
+
{ 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 }
|
|
604
|
+
]
|
|
308
605
|
}
|
|
309
606
|
];
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
607
|
+
new Set(BASE_TEMPLATES.map((t) => t.id));
|
|
608
|
+
const cleanPath = (path) => path.split("/").map((s) => s.trim()).filter(Boolean).join("/");
|
|
609
|
+
const parentOf = (path) => path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "";
|
|
610
|
+
const isUnder = (path, base) => path === base || path.startsWith(`${base}/`);
|
|
611
|
+
const renamePath = (path, from, to) => isUnder(path, from) ? to + path.slice(from.length) : path;
|
|
612
|
+
const folderTree = (paths) => {
|
|
613
|
+
const all3 = /* @__PURE__ */ new Set();
|
|
614
|
+
for (const p of paths.map(cleanPath).filter(Boolean)) {
|
|
615
|
+
let cur = p;
|
|
616
|
+
while (cur) {
|
|
617
|
+
all3.add(cur);
|
|
618
|
+
cur = parentOf(cur);
|
|
318
619
|
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
620
|
+
}
|
|
621
|
+
return [...all3].sort((a, b) => a.localeCompare(b, "es"));
|
|
622
|
+
};
|
|
623
|
+
class TemplateInputError extends Error {
|
|
624
|
+
}
|
|
625
|
+
const LAYER_TYPES = ["text", "list", "quote", "rect", "shape", "badge", "logo", "image", "icon", "avatar", "qr"];
|
|
626
|
+
const MAX_LAYERS = 200;
|
|
627
|
+
const fail$1 = (message) => {
|
|
628
|
+
throw new TemplateInputError(message);
|
|
629
|
+
};
|
|
630
|
+
const hasDataUrl = (value) => {
|
|
631
|
+
if (typeof value === "string") return value.startsWith("data:");
|
|
632
|
+
if (Array.isArray(value)) return value.some(hasDataUrl);
|
|
633
|
+
if (value && typeof value === "object") return Object.values(value).some(hasDataUrl);
|
|
634
|
+
return false;
|
|
635
|
+
};
|
|
636
|
+
const name = (v) => {
|
|
637
|
+
const n = typeof v === "string" ? v.trim() : "";
|
|
638
|
+
if (!n || n.length > 120) fail$1("El nombre debe tener entre 1 y 120 caracteres.");
|
|
639
|
+
return n;
|
|
640
|
+
};
|
|
641
|
+
const size = (v) => {
|
|
642
|
+
if (!Number.isInteger(v) || v < 100 || v > 4e3) fail$1("Las medidas deben ser enteros de 100 a 4000 px.");
|
|
643
|
+
return v;
|
|
644
|
+
};
|
|
645
|
+
const nonNegative = (v, label) => {
|
|
646
|
+
if (typeof v !== "number" || !Number.isFinite(v) || v < 0) fail$1(`${label} debe ser un número positivo.`);
|
|
647
|
+
return v;
|
|
648
|
+
};
|
|
649
|
+
const layers = (v) => {
|
|
650
|
+
if (!Array.isArray(v) || v.length > MAX_LAYERS) fail$1(`Las capas deben ser una lista de hasta ${MAX_LAYERS}.`);
|
|
651
|
+
v.forEach((l, i) => {
|
|
652
|
+
const layer = l ?? {};
|
|
653
|
+
if (typeof layer.id !== "string" || !layer.id) fail$1(`La capa ${i + 1} no tiene id.`);
|
|
654
|
+
if (!LAYER_TYPES.includes(layer.type)) fail$1(`La capa ${i + 1} tiene un tipo desconocido.`);
|
|
655
|
+
if (typeof layer.x !== "number" || typeof layer.y !== "number") fail$1(`La capa ${i + 1} no tiene posición.`);
|
|
656
|
+
});
|
|
657
|
+
if (hasDataUrl(v)) fail$1("Las imágenes deben guardarse en la Media Library, no dentro del template.");
|
|
658
|
+
return v;
|
|
659
|
+
};
|
|
660
|
+
const text = (v, fallback) => typeof v === "string" ? v : fallback;
|
|
661
|
+
const validateTemplate = (input) => {
|
|
662
|
+
const t = input ?? {};
|
|
663
|
+
const out = {
|
|
664
|
+
name: name(t.name),
|
|
665
|
+
folder: cleanPath(text(t.folder, "")),
|
|
666
|
+
width: size(t.width),
|
|
667
|
+
height: size(t.height),
|
|
668
|
+
background: text(t.background, "#FFFFFF"),
|
|
669
|
+
safeMargin: nonNegative(t.safeMargin ?? 0, "El margen seguro"),
|
|
670
|
+
gridUnit: nonNegative(t.gridUnit ?? 60, "La cuadrícula"),
|
|
671
|
+
layers: layers(t.layers)
|
|
672
|
+
};
|
|
673
|
+
if (typeof t.baseId === "string" && t.baseId) out.baseId = t.baseId;
|
|
674
|
+
return out;
|
|
675
|
+
};
|
|
676
|
+
const validateTemplatePatch = (input) => {
|
|
677
|
+
const t = input ?? {};
|
|
678
|
+
const out = {};
|
|
679
|
+
if ("name" in t) out.name = name(t.name);
|
|
680
|
+
if ("folder" in t) out.folder = cleanPath(text(t.folder, ""));
|
|
681
|
+
if ("width" in t) out.width = size(t.width);
|
|
682
|
+
if ("height" in t) out.height = size(t.height);
|
|
683
|
+
if ("background" in t) out.background = text(t.background, "#FFFFFF");
|
|
684
|
+
if ("safeMargin" in t) out.safeMargin = nonNegative(t.safeMargin, "El margen seguro");
|
|
685
|
+
if ("gridUnit" in t) out.gridUnit = nonNegative(t.gridUnit, "La cuadrícula");
|
|
686
|
+
if ("layers" in t) out.layers = layers(t.layers);
|
|
687
|
+
if (!Object.keys(out).length) fail$1("Nada que actualizar.");
|
|
688
|
+
return out;
|
|
689
|
+
};
|
|
690
|
+
const TEMPLATE_UID = "plugin::strapi-content-generator-gemini.template";
|
|
691
|
+
const FOLDERS_KEY = "TEMPLATE_FOLDERS";
|
|
692
|
+
class TemplateNotFoundError extends Error {
|
|
693
|
+
}
|
|
694
|
+
const FIELDS = ["name", "folder", "width", "height", "background", "safeMargin", "gridUnit", "layers", "baseId", "replacesBase"];
|
|
695
|
+
const BASE_IDS = new Set(BASE_TEMPLATES.map((t) => t.id));
|
|
696
|
+
const checkBaseId = (baseId) => {
|
|
697
|
+
if (typeof baseId !== "string" || !BASE_IDS.has(baseId)) throw new TemplateInputError("Plantilla base desconocida.");
|
|
698
|
+
return baseId;
|
|
699
|
+
};
|
|
700
|
+
const toStored = (d) => {
|
|
701
|
+
const out = { documentId: d.documentId, updatedAt: d.updatedAt };
|
|
702
|
+
for (const f of FIELDS) if (d[f] !== void 0 && d[f] !== null) out[f] = d[f];
|
|
703
|
+
out.folder = typeof d.folder === "string" ? d.folder : "";
|
|
704
|
+
return out;
|
|
705
|
+
};
|
|
706
|
+
const createTemplatesService = (docs, store) => {
|
|
707
|
+
const all3 = async () => (await docs.findMany({})).map(toStored);
|
|
708
|
+
const storedFolders = async () => {
|
|
709
|
+
const v = await store.get({ key: FOLDERS_KEY });
|
|
710
|
+
return Array.isArray(v) ? v : [];
|
|
711
|
+
};
|
|
712
|
+
const saveFolders = (folders) => store.set({ key: FOLDERS_KEY, value: folderTree(folders) });
|
|
713
|
+
const tree = async () => folderTree([...await storedFolders(), ...(await all3()).map((t) => t.folder)]);
|
|
714
|
+
const mustExist = async (documentId) => {
|
|
715
|
+
const d = await docs.findOne({ documentId });
|
|
716
|
+
if (!d) throw new TemplateNotFoundError("El template no existe o fue eliminado.");
|
|
717
|
+
return d;
|
|
718
|
+
};
|
|
719
|
+
const moveTemplates = async (path, to) => {
|
|
720
|
+
for (const t of await all3()) {
|
|
721
|
+
if (isUnder(t.folder, path)) await docs.update({ documentId: t.documentId, data: { folder: to(t.folder) } });
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
return {
|
|
725
|
+
async list() {
|
|
726
|
+
return (await all3()).sort((a, b) => a.name.localeCompare(b.name, "es", { sensitivity: "base" }));
|
|
727
|
+
},
|
|
728
|
+
async findOne(documentId) {
|
|
729
|
+
return toStored(await mustExist(documentId));
|
|
730
|
+
},
|
|
731
|
+
async create(input) {
|
|
732
|
+
return toStored(await docs.create({ data: validateTemplate(input) }));
|
|
733
|
+
},
|
|
734
|
+
async update(documentId, patch) {
|
|
735
|
+
const data = validateTemplatePatch(patch);
|
|
736
|
+
await mustExist(documentId);
|
|
737
|
+
return toStored(await docs.update({ documentId, data }));
|
|
738
|
+
},
|
|
739
|
+
async remove(documentId) {
|
|
740
|
+
await mustExist(documentId);
|
|
741
|
+
await docs.delete({ documentId });
|
|
742
|
+
},
|
|
743
|
+
/**
|
|
744
|
+
* Guarda la versión editada de una plantilla base (S4.15): la crea la primera vez y después la
|
|
745
|
+
* actualiza. Vive en la raíz y conserva la base como origen.
|
|
746
|
+
*/
|
|
747
|
+
async saveBase(baseId, input) {
|
|
748
|
+
const id = checkBaseId(baseId);
|
|
749
|
+
const data = { ...validateTemplate(input), folder: "", baseId: id, replacesBase: id };
|
|
750
|
+
const current = (await all3()).find((t) => t.replacesBase === id);
|
|
751
|
+
return toStored(current ? await docs.update({ documentId: current.documentId, data }) : await docs.create({ data }));
|
|
752
|
+
},
|
|
753
|
+
/** Vuelve a la versión de InterWare: borra la editada, si existe. */
|
|
754
|
+
async restoreBase(baseId) {
|
|
755
|
+
const id = checkBaseId(baseId);
|
|
756
|
+
const current = (await all3()).find((t) => t.replacesBase === id);
|
|
757
|
+
if (current) await docs.delete({ documentId: current.documentId });
|
|
758
|
+
},
|
|
759
|
+
folders: tree,
|
|
760
|
+
async createFolder(path) {
|
|
761
|
+
const p = cleanPath(typeof path === "string" ? path : "");
|
|
762
|
+
if (!p) throw new TemplateInputError("Escribe el nombre de la carpeta.");
|
|
763
|
+
if ((await tree()).includes(p)) throw new TemplateInputError("Ya existe una carpeta con ese nombre.");
|
|
764
|
+
await saveFolders([...await storedFolders(), p]);
|
|
765
|
+
return tree();
|
|
766
|
+
},
|
|
767
|
+
async renameFolder(from, to) {
|
|
768
|
+
const src = cleanPath(typeof from === "string" ? from : "");
|
|
769
|
+
const dst = cleanPath(typeof to === "string" ? to : "");
|
|
770
|
+
if (!src || !dst) throw new TemplateInputError("Indica la carpeta y su nombre nuevo.");
|
|
771
|
+
if (src === dst) return tree();
|
|
772
|
+
const current = await tree();
|
|
773
|
+
if (!current.includes(src)) throw new TemplateInputError("La carpeta no existe.");
|
|
774
|
+
if (current.includes(dst) || isUnder(dst, src)) throw new TemplateInputError("Ya existe una carpeta con ese nombre.");
|
|
775
|
+
await saveFolders(current.map((p) => renamePath(p, src, dst)));
|
|
776
|
+
await moveTemplates(src, (f) => renamePath(f, src, dst));
|
|
777
|
+
return tree();
|
|
778
|
+
},
|
|
779
|
+
async deleteFolder(path) {
|
|
780
|
+
const p = cleanPath(typeof path === "string" ? path : "");
|
|
781
|
+
if (!p) throw new TemplateInputError("No se puede eliminar la raíz.");
|
|
782
|
+
const target = parentOf(p);
|
|
783
|
+
await saveFolders((await tree()).filter((f) => !isUnder(f, p)));
|
|
784
|
+
await moveTemplates(p, () => target);
|
|
785
|
+
return tree();
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
};
|
|
789
|
+
const templates$1 = ({ strapi }) => {
|
|
790
|
+
const docs = () => strapi.documents(TEMPLATE_UID);
|
|
791
|
+
const store = () => strapi.store({ type: "plugin", name: "strapi-content-generator-gemini" });
|
|
792
|
+
return createTemplatesService(
|
|
793
|
+
{
|
|
794
|
+
findMany: (p) => docs().findMany(p),
|
|
795
|
+
findOne: (p) => docs().findOne(p),
|
|
796
|
+
create: (p) => docs().create(p),
|
|
797
|
+
update: (p) => docs().update(p),
|
|
798
|
+
delete: (p) => docs().delete(p)
|
|
799
|
+
},
|
|
800
|
+
{ get: (p) => store().get(p), set: (p) => store().set(p) }
|
|
801
|
+
);
|
|
802
|
+
};
|
|
803
|
+
const fail = (ctx, status, name2, message) => {
|
|
804
|
+
ctx.status = status;
|
|
805
|
+
ctx.body = { data: null, error: { status, name: name2, message } };
|
|
806
|
+
};
|
|
807
|
+
const templates = ({ strapi }) => {
|
|
808
|
+
const svc = () => strapi.plugin("strapi-content-generator-gemini").service("templates");
|
|
809
|
+
const run = async (ctx, work, status = 200) => {
|
|
810
|
+
try {
|
|
811
|
+
ctx.body = await work();
|
|
812
|
+
ctx.status = status;
|
|
813
|
+
} catch (err) {
|
|
814
|
+
if (err instanceof TemplateInputError) return fail(ctx, 400, "BadRequestError", err.message);
|
|
815
|
+
if (err instanceof TemplateNotFoundError) return fail(ctx, 404, "NotFoundError", err.message);
|
|
816
|
+
strapi.log.error(`[templates] ${err instanceof Error ? err.message : String(err)}`);
|
|
817
|
+
return fail(ctx, 500, "InternalServerError", "No se pudo completar la operación con los templates.");
|
|
327
818
|
}
|
|
819
|
+
};
|
|
820
|
+
const body = (ctx) => ctx.request.body ?? {};
|
|
821
|
+
return {
|
|
822
|
+
list: (ctx) => run(ctx, async () => ({ templates: await svc().list() })),
|
|
823
|
+
create: (ctx) => run(ctx, () => svc().create(body(ctx)), 201),
|
|
824
|
+
findOne: (ctx) => run(ctx, () => svc().findOne(ctx.params.documentId)),
|
|
825
|
+
update: (ctx) => run(ctx, () => svc().update(ctx.params.documentId, body(ctx))),
|
|
826
|
+
remove: (ctx) => run(ctx, async () => {
|
|
827
|
+
await svc().remove(ctx.params.documentId);
|
|
828
|
+
return { ok: true };
|
|
829
|
+
}),
|
|
830
|
+
saveBase: (ctx) => run(ctx, () => svc().saveBase(ctx.params.baseId, body(ctx))),
|
|
831
|
+
restoreBase: (ctx) => run(ctx, async () => {
|
|
832
|
+
await svc().restoreBase(ctx.params.baseId);
|
|
833
|
+
return { ok: true };
|
|
834
|
+
}),
|
|
835
|
+
folders: (ctx) => run(ctx, async () => ({ folders: await svc().folders() })),
|
|
836
|
+
createFolder: (ctx) => run(ctx, async () => ({ folders: await svc().createFolder(body(ctx).path) })),
|
|
837
|
+
renameFolder: (ctx) => run(ctx, async () => ({ folders: await svc().renameFolder(body(ctx).from, body(ctx).to) })),
|
|
838
|
+
deleteFolder: (ctx) => run(ctx, async () => ({ folders: await svc().deleteFolder(body(ctx).path) }))
|
|
839
|
+
};
|
|
840
|
+
};
|
|
841
|
+
const controllers = {
|
|
842
|
+
controller,
|
|
843
|
+
config: config$1,
|
|
844
|
+
"image-studio": imageStudio,
|
|
845
|
+
templates
|
|
846
|
+
};
|
|
847
|
+
const middlewares = {};
|
|
848
|
+
const policies = {};
|
|
849
|
+
const ACCESS_ACTION = "plugin::strapi-content-generator-gemini.access";
|
|
850
|
+
const ADMIN_ACCESS_POLICIES = [
|
|
851
|
+
"admin::isAuthenticatedAdmin",
|
|
852
|
+
{
|
|
853
|
+
name: "admin::hasPermissions",
|
|
854
|
+
config: { actions: [ACCESS_ACTION] }
|
|
328
855
|
}
|
|
329
856
|
];
|
|
857
|
+
const config = { policies: ADMIN_ACCESS_POLICIES };
|
|
858
|
+
const admin = [
|
|
859
|
+
{ method: "GET", path: "/posts", handler: "controller.getArticles", config },
|
|
860
|
+
{ method: "GET", path: "/categories", handler: "controller.getCategories", config },
|
|
861
|
+
{ method: "GET", path: "/users", handler: "controller.getUsers", config },
|
|
862
|
+
{ method: "POST", path: "/download-file", handler: "controller.downloadFile", config },
|
|
863
|
+
{ method: "POST", path: "/generate-article", handler: "controller.generateArticle", config },
|
|
864
|
+
{ method: "POST", path: "/generate-image", handler: "controller.generateImageForArticle", config },
|
|
865
|
+
{ method: "GET", path: "/image-studio/models", handler: "image-studio.models", config },
|
|
866
|
+
{ method: "POST", path: "/image-studio/generate", handler: "image-studio.generate", config },
|
|
867
|
+
{ method: "POST", path: "/image-studio/edit", handler: "image-studio.edit", config },
|
|
868
|
+
{ method: "POST", path: "/image-studio/expand", handler: "image-studio.expand", config },
|
|
869
|
+
{ method: "POST", path: "/generate-video-with-scenes", handler: "controller.generateVideo", config },
|
|
870
|
+
{ method: "POST", path: "/publish-linkedin", handler: "controller.publishToLinkedIn", config },
|
|
871
|
+
{ method: "POST", path: "/publish-facebook", handler: "controller.publishToFacebook", config },
|
|
872
|
+
{ method: "GET", path: "/templates", handler: "templates.list", config },
|
|
873
|
+
{ method: "POST", path: "/templates", handler: "templates.create", config },
|
|
874
|
+
{ method: "GET", path: "/templates/:documentId", handler: "templates.findOne", config },
|
|
875
|
+
{ method: "PUT", path: "/templates/:documentId", handler: "templates.update", config },
|
|
876
|
+
{ method: "DELETE", path: "/templates/:documentId", handler: "templates.remove", config },
|
|
877
|
+
{ method: "PUT", path: "/templates/base/:baseId", handler: "templates.saveBase", config },
|
|
878
|
+
{ method: "DELETE", path: "/templates/base/:baseId", handler: "templates.restoreBase", config },
|
|
879
|
+
{ method: "GET", path: "/template-folders", handler: "templates.folders", config },
|
|
880
|
+
{ method: "POST", path: "/template-folders", handler: "templates.createFolder", config },
|
|
881
|
+
{ method: "POST", path: "/template-folders/rename", handler: "templates.renameFolder", config },
|
|
882
|
+
{ method: "POST", path: "/template-folders/delete", handler: "templates.deleteFolder", config },
|
|
883
|
+
{ method: "GET", path: "/config", handler: "config.get", config },
|
|
884
|
+
{ method: "POST", path: "/config", handler: "config.set", config }
|
|
885
|
+
];
|
|
886
|
+
const contentApi = [];
|
|
330
887
|
const routes = {
|
|
331
888
|
"content-api": {
|
|
332
889
|
type: "content-api",
|
|
@@ -345,9 +902,26 @@ function bind(fn, thisArg) {
|
|
|
345
902
|
const { toString } = Object.prototype;
|
|
346
903
|
const { getPrototypeOf } = Object;
|
|
347
904
|
const { iterator, toStringTag } = Symbol;
|
|
905
|
+
const hasOwnProperty = (({ hasOwnProperty: hasOwnProperty2 }) => (obj, prop) => hasOwnProperty2.call(obj, prop))(Object.prototype);
|
|
906
|
+
const hasOwnInPrototypeChain = (thing, prop) => {
|
|
907
|
+
let obj = thing;
|
|
908
|
+
const seen = [];
|
|
909
|
+
while (obj != null && obj !== Object.prototype) {
|
|
910
|
+
if (seen.indexOf(obj) !== -1) {
|
|
911
|
+
return false;
|
|
912
|
+
}
|
|
913
|
+
seen.push(obj);
|
|
914
|
+
if (hasOwnProperty(obj, prop)) {
|
|
915
|
+
return true;
|
|
916
|
+
}
|
|
917
|
+
obj = getPrototypeOf(obj);
|
|
918
|
+
}
|
|
919
|
+
return false;
|
|
920
|
+
};
|
|
921
|
+
const getSafeProp = (obj, prop) => obj != null && hasOwnInPrototypeChain(obj, prop) ? obj[prop] : void 0;
|
|
348
922
|
const kindOf = /* @__PURE__ */ ((cache) => (thing) => {
|
|
349
|
-
const
|
|
350
|
-
return cache[
|
|
923
|
+
const str2 = toString.call(thing);
|
|
924
|
+
return cache[str2] || (cache[str2] = str2.slice(8, -1).toLowerCase());
|
|
351
925
|
})(/* @__PURE__ */ Object.create(null));
|
|
352
926
|
const kindOfTest = (type) => {
|
|
353
927
|
type = type.toLowerCase();
|
|
@@ -375,11 +949,14 @@ const isNumber = typeOfTest("number");
|
|
|
375
949
|
const isObject = (thing) => thing !== null && typeof thing === "object";
|
|
376
950
|
const isBoolean = (thing) => thing === true || thing === false;
|
|
377
951
|
const isPlainObject = (val) => {
|
|
378
|
-
if (
|
|
952
|
+
if (!isObject(val)) {
|
|
379
953
|
return false;
|
|
380
954
|
}
|
|
381
955
|
const prototype2 = getPrototypeOf(val);
|
|
382
|
-
return (prototype2 === null || prototype2 === Object.prototype ||
|
|
956
|
+
return (prototype2 === null || prototype2 === Object.prototype || getPrototypeOf(prototype2) === null) && // Treat any genuine (non-Object.prototype-polluted) Symbol.toStringTag or
|
|
957
|
+
// Symbol.iterator as evidence the value is a tagged/iterable type rather
|
|
958
|
+
// than a plain object, while ignoring keys injected onto Object.prototype.
|
|
959
|
+
!hasOwnInPrototypeChain(val, toStringTag) && !hasOwnInPrototypeChain(val, iterator);
|
|
383
960
|
};
|
|
384
961
|
const isEmptyObject = (val) => {
|
|
385
962
|
if (!isObject(val) || isBuffer(val)) {
|
|
@@ -393,17 +970,42 @@ const isEmptyObject = (val) => {
|
|
|
393
970
|
};
|
|
394
971
|
const isDate = kindOfTest("Date");
|
|
395
972
|
const isFile = kindOfTest("File");
|
|
973
|
+
const isReactNativeBlob = (value) => {
|
|
974
|
+
return !!(value && typeof value.uri !== "undefined");
|
|
975
|
+
};
|
|
976
|
+
const isReactNative = (formData) => formData && typeof formData.getParts !== "undefined";
|
|
396
977
|
const isBlob = kindOfTest("Blob");
|
|
397
978
|
const isFileList = kindOfTest("FileList");
|
|
398
979
|
const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
|
|
980
|
+
function getGlobal() {
|
|
981
|
+
if (typeof globalThis !== "undefined") return globalThis;
|
|
982
|
+
if (typeof self !== "undefined") return self;
|
|
983
|
+
if (typeof window !== "undefined") return window;
|
|
984
|
+
if (typeof global !== "undefined") return global;
|
|
985
|
+
return {};
|
|
986
|
+
}
|
|
987
|
+
const G = getGlobal();
|
|
988
|
+
const FormDataCtor = typeof G.FormData !== "undefined" ? G.FormData : void 0;
|
|
399
989
|
const isFormData = (thing) => {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
990
|
+
if (!thing) return false;
|
|
991
|
+
if (FormDataCtor && thing instanceof FormDataCtor) return true;
|
|
992
|
+
const proto = getPrototypeOf(thing);
|
|
993
|
+
if (!proto || proto === Object.prototype) return false;
|
|
994
|
+
if (!isFunction$1(thing.append)) return false;
|
|
995
|
+
const kind = kindOf(thing);
|
|
996
|
+
return kind === "formdata" || // detect form-data instance
|
|
997
|
+
kind === "object" && isFunction$1(thing.toString) && thing.toString() === "[object FormData]";
|
|
403
998
|
};
|
|
404
999
|
const isURLSearchParams = kindOfTest("URLSearchParams");
|
|
405
|
-
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
|
406
|
-
|
|
1000
|
+
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
|
1001
|
+
"ReadableStream",
|
|
1002
|
+
"Request",
|
|
1003
|
+
"Response",
|
|
1004
|
+
"Headers"
|
|
1005
|
+
].map(kindOfTest);
|
|
1006
|
+
const trim = (str2) => {
|
|
1007
|
+
return str2.trim ? str2.trim() : str2.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "");
|
|
1008
|
+
};
|
|
407
1009
|
function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
|
408
1010
|
if (obj === null || typeof obj === "undefined") {
|
|
409
1011
|
return;
|
|
@@ -451,13 +1053,17 @@ const _global = (() => {
|
|
|
451
1053
|
return typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : global;
|
|
452
1054
|
})();
|
|
453
1055
|
const isContextDefined = (context) => !isUndefined(context) && context !== _global;
|
|
454
|
-
function merge() {
|
|
1056
|
+
function merge(...objs) {
|
|
455
1057
|
const { caseless, skipUndefined } = isContextDefined(this) && this || {};
|
|
456
1058
|
const result = {};
|
|
457
1059
|
const assignValue = (val, key) => {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
1060
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
const targetKey = caseless && typeof key === "string" && findKey(result, key) || key;
|
|
1064
|
+
const existing = hasOwnProperty(result, targetKey) ? result[targetKey] : void 0;
|
|
1065
|
+
if (isPlainObject(existing) && isPlainObject(val)) {
|
|
1066
|
+
result[targetKey] = merge(existing, val);
|
|
461
1067
|
} else if (isPlainObject(val)) {
|
|
462
1068
|
result[targetKey] = merge({}, val);
|
|
463
1069
|
} else if (isArray(val)) {
|
|
@@ -466,19 +1072,51 @@ function merge() {
|
|
|
466
1072
|
result[targetKey] = val;
|
|
467
1073
|
}
|
|
468
1074
|
};
|
|
469
|
-
for (let i = 0, l =
|
|
470
|
-
|
|
1075
|
+
for (let i = 0, l = objs.length; i < l; i++) {
|
|
1076
|
+
const source = objs[i];
|
|
1077
|
+
if (!source || isBuffer(source)) {
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
forEach(source, assignValue);
|
|
1081
|
+
if (typeof source !== "object" || isArray(source)) {
|
|
1082
|
+
continue;
|
|
1083
|
+
}
|
|
1084
|
+
const symbols = Object.getOwnPropertySymbols(source);
|
|
1085
|
+
for (let j = 0; j < symbols.length; j++) {
|
|
1086
|
+
const symbol = symbols[j];
|
|
1087
|
+
if (propertyIsEnumerable.call(source, symbol)) {
|
|
1088
|
+
assignValue(source[symbol], symbol);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
471
1091
|
}
|
|
472
1092
|
return result;
|
|
473
1093
|
}
|
|
474
1094
|
const extend = (a, b, thisArg, { allOwnKeys } = {}) => {
|
|
475
|
-
forEach(
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
1095
|
+
forEach(
|
|
1096
|
+
b,
|
|
1097
|
+
(val, key) => {
|
|
1098
|
+
if (thisArg && isFunction$1(val)) {
|
|
1099
|
+
Object.defineProperty(a, key, {
|
|
1100
|
+
// Null-proto descriptor so a polluted Object.prototype.get cannot
|
|
1101
|
+
// hijack defineProperty's accessor-vs-data resolution.
|
|
1102
|
+
__proto__: null,
|
|
1103
|
+
value: bind(val, thisArg),
|
|
1104
|
+
writable: true,
|
|
1105
|
+
enumerable: true,
|
|
1106
|
+
configurable: true
|
|
1107
|
+
});
|
|
1108
|
+
} else {
|
|
1109
|
+
Object.defineProperty(a, key, {
|
|
1110
|
+
__proto__: null,
|
|
1111
|
+
value: val,
|
|
1112
|
+
writable: true,
|
|
1113
|
+
enumerable: true,
|
|
1114
|
+
configurable: true
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
},
|
|
1118
|
+
{ allOwnKeys }
|
|
1119
|
+
);
|
|
482
1120
|
return a;
|
|
483
1121
|
};
|
|
484
1122
|
const stripBOM = (content) => {
|
|
@@ -487,10 +1125,17 @@ const stripBOM = (content) => {
|
|
|
487
1125
|
}
|
|
488
1126
|
return content;
|
|
489
1127
|
};
|
|
490
|
-
const inherits = (constructor, superConstructor, props,
|
|
491
|
-
constructor.prototype = Object.create(superConstructor.prototype,
|
|
492
|
-
constructor.prototype
|
|
1128
|
+
const inherits = (constructor, superConstructor, props, descriptors) => {
|
|
1129
|
+
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
|
1130
|
+
Object.defineProperty(constructor.prototype, "constructor", {
|
|
1131
|
+
__proto__: null,
|
|
1132
|
+
value: constructor,
|
|
1133
|
+
writable: true,
|
|
1134
|
+
enumerable: false,
|
|
1135
|
+
configurable: true
|
|
1136
|
+
});
|
|
493
1137
|
Object.defineProperty(constructor, "super", {
|
|
1138
|
+
__proto__: null,
|
|
494
1139
|
value: superConstructor.prototype
|
|
495
1140
|
});
|
|
496
1141
|
props && Object.assign(constructor.prototype, props);
|
|
@@ -516,13 +1161,13 @@ const toFlatObject = (sourceObj, destObj, filter2, propFilter) => {
|
|
|
516
1161
|
} while (sourceObj && (!filter2 || filter2(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
|
517
1162
|
return destObj;
|
|
518
1163
|
};
|
|
519
|
-
const endsWith = (
|
|
520
|
-
|
|
521
|
-
if (position === void 0 || position >
|
|
522
|
-
position =
|
|
1164
|
+
const endsWith = (str2, searchString, position) => {
|
|
1165
|
+
str2 = String(str2);
|
|
1166
|
+
if (position === void 0 || position > str2.length) {
|
|
1167
|
+
position = str2.length;
|
|
523
1168
|
}
|
|
524
1169
|
position -= searchString.length;
|
|
525
|
-
const lastIndex =
|
|
1170
|
+
const lastIndex = str2.indexOf(searchString, position);
|
|
526
1171
|
return lastIndex !== -1 && lastIndex === position;
|
|
527
1172
|
};
|
|
528
1173
|
const toArray = (thing) => {
|
|
@@ -550,42 +1195,39 @@ const forEachEntry = (obj, fn) => {
|
|
|
550
1195
|
fn.call(obj, pair[0], pair[1]);
|
|
551
1196
|
}
|
|
552
1197
|
};
|
|
553
|
-
const matchAll = (regExp,
|
|
1198
|
+
const matchAll = (regExp, str2) => {
|
|
554
1199
|
let matches;
|
|
555
1200
|
const arr = [];
|
|
556
|
-
while ((matches = regExp.exec(
|
|
1201
|
+
while ((matches = regExp.exec(str2)) !== null) {
|
|
557
1202
|
arr.push(matches);
|
|
558
1203
|
}
|
|
559
1204
|
return arr;
|
|
560
1205
|
};
|
|
561
1206
|
const isHTMLForm = kindOfTest("HTMLFormElement");
|
|
562
|
-
const toCamelCase = (
|
|
563
|
-
return
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
return p1.toUpperCase() + p2;
|
|
567
|
-
}
|
|
568
|
-
);
|
|
1207
|
+
const toCamelCase = (str2) => {
|
|
1208
|
+
return str2.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function replacer(m, p1, p2) {
|
|
1209
|
+
return p1.toUpperCase() + p2;
|
|
1210
|
+
});
|
|
569
1211
|
};
|
|
570
|
-
const
|
|
1212
|
+
const { propertyIsEnumerable } = Object.prototype;
|
|
571
1213
|
const isRegExp = kindOfTest("RegExp");
|
|
572
1214
|
const reduceDescriptors = (obj, reducer) => {
|
|
573
|
-
const
|
|
1215
|
+
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
|
574
1216
|
const reducedDescriptors = {};
|
|
575
|
-
forEach(
|
|
1217
|
+
forEach(descriptors, (descriptor, name2) => {
|
|
576
1218
|
let ret;
|
|
577
|
-
if ((ret = reducer(descriptor,
|
|
578
|
-
reducedDescriptors[
|
|
1219
|
+
if ((ret = reducer(descriptor, name2, obj)) !== false) {
|
|
1220
|
+
reducedDescriptors[name2] = ret || descriptor;
|
|
579
1221
|
}
|
|
580
1222
|
});
|
|
581
1223
|
Object.defineProperties(obj, reducedDescriptors);
|
|
582
1224
|
};
|
|
583
1225
|
const freezeMethods = (obj) => {
|
|
584
|
-
reduceDescriptors(obj, (descriptor,
|
|
585
|
-
if (isFunction$1(obj) && ["arguments", "caller", "callee"].
|
|
1226
|
+
reduceDescriptors(obj, (descriptor, name2) => {
|
|
1227
|
+
if (isFunction$1(obj) && ["arguments", "caller", "callee"].includes(name2)) {
|
|
586
1228
|
return false;
|
|
587
1229
|
}
|
|
588
|
-
const value = obj[
|
|
1230
|
+
const value = obj[name2];
|
|
589
1231
|
if (!isFunction$1(value)) return;
|
|
590
1232
|
descriptor.enumerable = false;
|
|
591
1233
|
if ("writable" in descriptor) {
|
|
@@ -594,7 +1236,7 @@ const freezeMethods = (obj) => {
|
|
|
594
1236
|
}
|
|
595
1237
|
if (!descriptor.set) {
|
|
596
1238
|
descriptor.set = () => {
|
|
597
|
-
throw Error("Can not rewrite read-only method '" +
|
|
1239
|
+
throw Error("Can not rewrite read-only method '" + name2 + "'");
|
|
598
1240
|
};
|
|
599
1241
|
}
|
|
600
1242
|
});
|
|
@@ -618,29 +1260,29 @@ function isSpecCompliantForm(thing) {
|
|
|
618
1260
|
return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === "FormData" && thing[iterator]);
|
|
619
1261
|
}
|
|
620
1262
|
const toJSONObject = (obj) => {
|
|
621
|
-
const
|
|
622
|
-
const visit = (source
|
|
1263
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
1264
|
+
const visit = (source) => {
|
|
623
1265
|
if (isObject(source)) {
|
|
624
|
-
if (
|
|
1266
|
+
if (visited.has(source)) {
|
|
625
1267
|
return;
|
|
626
1268
|
}
|
|
627
1269
|
if (isBuffer(source)) {
|
|
628
1270
|
return source;
|
|
629
1271
|
}
|
|
630
1272
|
if (!("toJSON" in source)) {
|
|
631
|
-
|
|
1273
|
+
visited.add(source);
|
|
632
1274
|
const target = isArray(source) ? [] : {};
|
|
633
1275
|
forEach(source, (value, key) => {
|
|
634
|
-
const reducedValue = visit(value
|
|
1276
|
+
const reducedValue = visit(value);
|
|
635
1277
|
!isUndefined(reducedValue) && (target[key] = reducedValue);
|
|
636
1278
|
});
|
|
637
|
-
|
|
1279
|
+
visited.delete(source);
|
|
638
1280
|
return target;
|
|
639
1281
|
}
|
|
640
1282
|
}
|
|
641
1283
|
return source;
|
|
642
1284
|
};
|
|
643
|
-
return visit(obj
|
|
1285
|
+
return visit(obj);
|
|
644
1286
|
};
|
|
645
1287
|
const isAsyncFn = kindOfTest("AsyncFunction");
|
|
646
1288
|
const isThenable = (thing) => thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
|
|
@@ -649,22 +1291,24 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
|
|
649
1291
|
return setImmediate;
|
|
650
1292
|
}
|
|
651
1293
|
return postMessageSupported ? ((token, callbacks) => {
|
|
652
|
-
_global.addEventListener(
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
1294
|
+
_global.addEventListener(
|
|
1295
|
+
"message",
|
|
1296
|
+
({ source, data }) => {
|
|
1297
|
+
if (source === _global && data === token) {
|
|
1298
|
+
callbacks.length && callbacks.shift()();
|
|
1299
|
+
}
|
|
1300
|
+
},
|
|
1301
|
+
false
|
|
1302
|
+
);
|
|
657
1303
|
return (cb) => {
|
|
658
1304
|
callbacks.push(cb);
|
|
659
1305
|
_global.postMessage(token, "*");
|
|
660
1306
|
};
|
|
661
1307
|
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
|
662
|
-
})(
|
|
663
|
-
typeof setImmediate === "function",
|
|
664
|
-
isFunction$1(_global.postMessage)
|
|
665
|
-
);
|
|
1308
|
+
})(typeof setImmediate === "function", isFunction$1(_global.postMessage));
|
|
666
1309
|
const asap = typeof queueMicrotask !== "undefined" ? queueMicrotask.bind(_global) : typeof process !== "undefined" && process.nextTick || _setImmediate;
|
|
667
1310
|
const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
|
|
1311
|
+
const isSafeIterable = (thing) => thing != null && hasOwnInPrototypeChain(thing, iterator) && isIterable(thing);
|
|
668
1312
|
const utils$1 = {
|
|
669
1313
|
isArray,
|
|
670
1314
|
isArrayBuffer,
|
|
@@ -684,6 +1328,8 @@ const utils$1 = {
|
|
|
684
1328
|
isUndefined,
|
|
685
1329
|
isDate,
|
|
686
1330
|
isFile,
|
|
1331
|
+
isReactNativeBlob,
|
|
1332
|
+
isReactNative,
|
|
687
1333
|
isBlob,
|
|
688
1334
|
isRegExp,
|
|
689
1335
|
isFunction: isFunction$1,
|
|
@@ -708,6 +1354,8 @@ const utils$1 = {
|
|
|
708
1354
|
hasOwnProperty,
|
|
709
1355
|
hasOwnProp: hasOwnProperty,
|
|
710
1356
|
// an alias to avoid ESLint no-prototype-builtins detection
|
|
1357
|
+
hasOwnInPrototypeChain,
|
|
1358
|
+
getSafeProp,
|
|
711
1359
|
reduceDescriptors,
|
|
712
1360
|
freezeMethods,
|
|
713
1361
|
toObjectSet,
|
|
@@ -723,94 +1371,479 @@ const utils$1 = {
|
|
|
723
1371
|
isThenable,
|
|
724
1372
|
setImmediate: _setImmediate,
|
|
725
1373
|
asap,
|
|
726
|
-
isIterable
|
|
727
|
-
|
|
728
|
-
function AxiosError$1(message, code, config2, request, response) {
|
|
729
|
-
Error.call(this);
|
|
730
|
-
if (Error.captureStackTrace) {
|
|
731
|
-
Error.captureStackTrace(this, this.constructor);
|
|
732
|
-
} else {
|
|
733
|
-
this.stack = new Error().stack;
|
|
734
|
-
}
|
|
735
|
-
this.message = message;
|
|
736
|
-
this.name = "AxiosError";
|
|
737
|
-
code && (this.code = code);
|
|
738
|
-
config2 && (this.config = config2);
|
|
739
|
-
request && (this.request = request);
|
|
740
|
-
if (response) {
|
|
741
|
-
this.response = response;
|
|
742
|
-
this.status = response.status ? response.status : null;
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
utils$1.inherits(AxiosError$1, Error, {
|
|
746
|
-
toJSON: function toJSON() {
|
|
747
|
-
return {
|
|
748
|
-
// Standard
|
|
749
|
-
message: this.message,
|
|
750
|
-
name: this.name,
|
|
751
|
-
// Microsoft
|
|
752
|
-
description: this.description,
|
|
753
|
-
number: this.number,
|
|
754
|
-
// Mozilla
|
|
755
|
-
fileName: this.fileName,
|
|
756
|
-
lineNumber: this.lineNumber,
|
|
757
|
-
columnNumber: this.columnNumber,
|
|
758
|
-
stack: this.stack,
|
|
759
|
-
// Axios
|
|
760
|
-
config: utils$1.toJSONObject(this.config),
|
|
761
|
-
code: this.code,
|
|
762
|
-
status: this.status
|
|
763
|
-
};
|
|
764
|
-
}
|
|
765
|
-
});
|
|
766
|
-
const prototype$1 = AxiosError$1.prototype;
|
|
767
|
-
const descriptors = {};
|
|
768
|
-
[
|
|
769
|
-
"ERR_BAD_OPTION_VALUE",
|
|
770
|
-
"ERR_BAD_OPTION",
|
|
771
|
-
"ECONNABORTED",
|
|
772
|
-
"ETIMEDOUT",
|
|
773
|
-
"ERR_NETWORK",
|
|
774
|
-
"ERR_FR_TOO_MANY_REDIRECTS",
|
|
775
|
-
"ERR_DEPRECATED",
|
|
776
|
-
"ERR_BAD_RESPONSE",
|
|
777
|
-
"ERR_BAD_REQUEST",
|
|
778
|
-
"ERR_CANCELED",
|
|
779
|
-
"ERR_NOT_SUPPORT",
|
|
780
|
-
"ERR_INVALID_URL"
|
|
781
|
-
// eslint-disable-next-line func-names
|
|
782
|
-
].forEach((code) => {
|
|
783
|
-
descriptors[code] = { value: code };
|
|
784
|
-
});
|
|
785
|
-
Object.defineProperties(AxiosError$1, descriptors);
|
|
786
|
-
Object.defineProperty(prototype$1, "isAxiosError", { value: true });
|
|
787
|
-
AxiosError$1.from = (error, code, config2, request, response, customProps) => {
|
|
788
|
-
const axiosError = Object.create(prototype$1);
|
|
789
|
-
utils$1.toFlatObject(error, axiosError, function filter2(obj) {
|
|
790
|
-
return obj !== Error.prototype;
|
|
791
|
-
}, (prop) => {
|
|
792
|
-
return prop !== "isAxiosError";
|
|
793
|
-
});
|
|
794
|
-
const msg = error && error.message ? error.message : "Error";
|
|
795
|
-
const errCode = code == null && error ? error.code : code;
|
|
796
|
-
AxiosError$1.call(axiosError, msg, errCode, config2, request, response);
|
|
797
|
-
if (error && axiosError.cause == null) {
|
|
798
|
-
Object.defineProperty(axiosError, "cause", { value: error, configurable: true });
|
|
799
|
-
}
|
|
800
|
-
axiosError.name = error && error.name || "Error";
|
|
801
|
-
customProps && Object.assign(axiosError, customProps);
|
|
802
|
-
return axiosError;
|
|
1374
|
+
isIterable,
|
|
1375
|
+
isSafeIterable
|
|
803
1376
|
};
|
|
804
|
-
const
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
1377
|
+
const ignoreDuplicateOf = utils$1.toObjectSet([
|
|
1378
|
+
"age",
|
|
1379
|
+
"authorization",
|
|
1380
|
+
"content-length",
|
|
1381
|
+
"content-type",
|
|
1382
|
+
"etag",
|
|
1383
|
+
"expires",
|
|
1384
|
+
"from",
|
|
1385
|
+
"host",
|
|
1386
|
+
"if-modified-since",
|
|
1387
|
+
"if-unmodified-since",
|
|
1388
|
+
"last-modified",
|
|
1389
|
+
"location",
|
|
1390
|
+
"max-forwards",
|
|
1391
|
+
"proxy-authorization",
|
|
1392
|
+
"referer",
|
|
1393
|
+
"retry-after",
|
|
1394
|
+
"user-agent"
|
|
1395
|
+
]);
|
|
1396
|
+
const parseHeaders = (rawHeaders) => {
|
|
1397
|
+
const parsed = {};
|
|
1398
|
+
let key;
|
|
1399
|
+
let val;
|
|
1400
|
+
let i;
|
|
1401
|
+
rawHeaders && rawHeaders.split("\n").forEach(function parser(line) {
|
|
1402
|
+
i = line.indexOf(":");
|
|
1403
|
+
key = line.substring(0, i).trim().toLowerCase();
|
|
1404
|
+
val = line.substring(i + 1).trim();
|
|
1405
|
+
if (!key || parsed[key] && ignoreDuplicateOf[key]) {
|
|
1406
|
+
return;
|
|
1407
|
+
}
|
|
1408
|
+
if (key === "set-cookie") {
|
|
1409
|
+
if (parsed[key]) {
|
|
1410
|
+
parsed[key].push(val);
|
|
1411
|
+
} else {
|
|
1412
|
+
parsed[key] = [val];
|
|
1413
|
+
}
|
|
1414
|
+
} else {
|
|
1415
|
+
parsed[key] = parsed[key] ? parsed[key] + ", " + val : val;
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
1418
|
+
return parsed;
|
|
1419
|
+
};
|
|
1420
|
+
function trimSPorHTAB(str2) {
|
|
1421
|
+
let start = 0;
|
|
1422
|
+
let end = str2.length;
|
|
1423
|
+
while (start < end) {
|
|
1424
|
+
const code = str2.charCodeAt(start);
|
|
1425
|
+
if (code !== 9 && code !== 32) {
|
|
1426
|
+
break;
|
|
1427
|
+
}
|
|
1428
|
+
start += 1;
|
|
1429
|
+
}
|
|
1430
|
+
while (end > start) {
|
|
1431
|
+
const code = str2.charCodeAt(end - 1);
|
|
1432
|
+
if (code !== 9 && code !== 32) {
|
|
1433
|
+
break;
|
|
1434
|
+
}
|
|
1435
|
+
end -= 1;
|
|
1436
|
+
}
|
|
1437
|
+
return start === 0 && end === str2.length ? str2 : str2.slice(start, end);
|
|
1438
|
+
}
|
|
1439
|
+
const INVALID_UNICODE_HEADER_VALUE_CHARS = new RegExp("[\\u0000-\\u0008\\u000a-\\u001f\\u007f]+", "g");
|
|
1440
|
+
const INVALID_BYTE_STRING_HEADER_VALUE_CHARS = new RegExp("[^\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+", "g");
|
|
1441
|
+
function sanitizeValue(value, invalidChars) {
|
|
1442
|
+
if (utils$1.isArray(value)) {
|
|
1443
|
+
return value.map((item) => sanitizeValue(item, invalidChars));
|
|
1444
|
+
}
|
|
1445
|
+
return trimSPorHTAB(String(value).replace(invalidChars, ""));
|
|
1446
|
+
}
|
|
1447
|
+
const sanitizeHeaderValue = (value) => sanitizeValue(value, INVALID_UNICODE_HEADER_VALUE_CHARS);
|
|
1448
|
+
const sanitizeByteStringHeaderValue = (value) => sanitizeValue(value, INVALID_BYTE_STRING_HEADER_VALUE_CHARS);
|
|
1449
|
+
function toByteStringHeaderObject(headers) {
|
|
1450
|
+
const byteStringHeaders = /* @__PURE__ */ Object.create(null);
|
|
1451
|
+
utils$1.forEach(headers.toJSON(), (value, header) => {
|
|
1452
|
+
byteStringHeaders[header] = sanitizeByteStringHeaderValue(value);
|
|
1453
|
+
});
|
|
1454
|
+
return byteStringHeaders;
|
|
1455
|
+
}
|
|
1456
|
+
const $internals = Symbol("internals");
|
|
1457
|
+
function normalizeHeader(header) {
|
|
1458
|
+
return header && String(header).trim().toLowerCase();
|
|
1459
|
+
}
|
|
1460
|
+
function normalizeValue(value) {
|
|
1461
|
+
if (value === false || value == null) {
|
|
1462
|
+
return value;
|
|
1463
|
+
}
|
|
1464
|
+
return utils$1.isArray(value) ? value.map(normalizeValue) : sanitizeHeaderValue(String(value));
|
|
1465
|
+
}
|
|
1466
|
+
function parseTokens(str2) {
|
|
1467
|
+
const tokens = /* @__PURE__ */ Object.create(null);
|
|
1468
|
+
const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
|
|
1469
|
+
let match;
|
|
1470
|
+
while (match = tokensRE.exec(str2)) {
|
|
1471
|
+
tokens[match[1]] = match[2];
|
|
1472
|
+
}
|
|
1473
|
+
return tokens;
|
|
1474
|
+
}
|
|
1475
|
+
const isValidHeaderName = (str2) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str2.trim());
|
|
1476
|
+
function matchHeaderValue(context, value, header, filter2, isHeaderNameFilter) {
|
|
1477
|
+
if (utils$1.isFunction(filter2)) {
|
|
1478
|
+
return filter2.call(this, value, header);
|
|
1479
|
+
}
|
|
1480
|
+
if (isHeaderNameFilter) {
|
|
1481
|
+
value = header;
|
|
1482
|
+
}
|
|
1483
|
+
if (!utils$1.isString(value)) return;
|
|
1484
|
+
if (utils$1.isString(filter2)) {
|
|
1485
|
+
return value.indexOf(filter2) !== -1;
|
|
1486
|
+
}
|
|
1487
|
+
if (utils$1.isRegExp(filter2)) {
|
|
1488
|
+
return filter2.test(value);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
function formatHeader(header) {
|
|
1492
|
+
return header.trim().toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str2) => {
|
|
1493
|
+
return char.toUpperCase() + str2;
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
function buildAccessors(obj, header) {
|
|
1497
|
+
const accessorName = utils$1.toCamelCase(" " + header);
|
|
1498
|
+
["get", "set", "has"].forEach((methodName) => {
|
|
1499
|
+
Object.defineProperty(obj, methodName + accessorName, {
|
|
1500
|
+
// Null-proto descriptor so a polluted Object.prototype.get cannot turn
|
|
1501
|
+
// this data descriptor into an accessor descriptor on the way in.
|
|
1502
|
+
__proto__: null,
|
|
1503
|
+
value: function(arg1, arg2, arg3) {
|
|
1504
|
+
return this[methodName].call(this, header, arg1, arg2, arg3);
|
|
1505
|
+
},
|
|
1506
|
+
configurable: true
|
|
1507
|
+
});
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
let AxiosHeaders$1 = class AxiosHeaders {
|
|
1511
|
+
constructor(headers) {
|
|
1512
|
+
headers && this.set(headers);
|
|
1513
|
+
}
|
|
1514
|
+
set(header, valueOrRewrite, rewrite) {
|
|
1515
|
+
const self2 = this;
|
|
1516
|
+
function setHeader(_value, _header, _rewrite) {
|
|
1517
|
+
const lHeader = normalizeHeader(_header);
|
|
1518
|
+
if (!lHeader) {
|
|
1519
|
+
return;
|
|
1520
|
+
}
|
|
1521
|
+
const key = utils$1.findKey(self2, lHeader);
|
|
1522
|
+
if (!key || self2[key] === void 0 || _rewrite === true || _rewrite === void 0 && self2[key] !== false) {
|
|
1523
|
+
self2[key || _header] = normalizeValue(_value);
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
const setHeaders = (headers, _rewrite) => utils$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
|
|
1527
|
+
if (utils$1.isPlainObject(header) || header instanceof this.constructor) {
|
|
1528
|
+
setHeaders(header, valueOrRewrite);
|
|
1529
|
+
} else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
|
1530
|
+
setHeaders(parseHeaders(header), valueOrRewrite);
|
|
1531
|
+
} else if (utils$1.isObject(header) && utils$1.isSafeIterable(header)) {
|
|
1532
|
+
let obj = /* @__PURE__ */ Object.create(null), dest, key;
|
|
1533
|
+
for (const entry of header) {
|
|
1534
|
+
if (!utils$1.isArray(entry)) {
|
|
1535
|
+
throw new TypeError("Object iterator must return a key-value pair");
|
|
1536
|
+
}
|
|
1537
|
+
key = entry[0];
|
|
1538
|
+
if (utils$1.hasOwnProp(obj, key)) {
|
|
1539
|
+
dest = obj[key];
|
|
1540
|
+
obj[key] = utils$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]];
|
|
1541
|
+
} else {
|
|
1542
|
+
obj[key] = entry[1];
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
setHeaders(obj, valueOrRewrite);
|
|
1546
|
+
} else {
|
|
1547
|
+
header != null && setHeader(valueOrRewrite, header, rewrite);
|
|
1548
|
+
}
|
|
1549
|
+
return this;
|
|
1550
|
+
}
|
|
1551
|
+
get(header, parser) {
|
|
1552
|
+
header = normalizeHeader(header);
|
|
1553
|
+
if (header) {
|
|
1554
|
+
const key = utils$1.findKey(this, header);
|
|
1555
|
+
if (key) {
|
|
1556
|
+
const value = this[key];
|
|
1557
|
+
if (!parser) {
|
|
1558
|
+
return value;
|
|
1559
|
+
}
|
|
1560
|
+
if (parser === true) {
|
|
1561
|
+
return parseTokens(value);
|
|
1562
|
+
}
|
|
1563
|
+
if (utils$1.isFunction(parser)) {
|
|
1564
|
+
return parser.call(this, value, key);
|
|
1565
|
+
}
|
|
1566
|
+
if (utils$1.isRegExp(parser)) {
|
|
1567
|
+
return parser.exec(value);
|
|
1568
|
+
}
|
|
1569
|
+
throw new TypeError("parser must be boolean|regexp|function");
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
has(header, matcher) {
|
|
1574
|
+
header = normalizeHeader(header);
|
|
1575
|
+
if (header) {
|
|
1576
|
+
const key = utils$1.findKey(this, header);
|
|
1577
|
+
return !!(key && this[key] !== void 0 && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
|
|
1578
|
+
}
|
|
1579
|
+
return false;
|
|
1580
|
+
}
|
|
1581
|
+
delete(header, matcher) {
|
|
1582
|
+
const self2 = this;
|
|
1583
|
+
let deleted = false;
|
|
1584
|
+
function deleteHeader(_header) {
|
|
1585
|
+
_header = normalizeHeader(_header);
|
|
1586
|
+
if (_header) {
|
|
1587
|
+
const key = utils$1.findKey(self2, _header);
|
|
1588
|
+
if (key && (!matcher || matchHeaderValue(self2, self2[key], key, matcher))) {
|
|
1589
|
+
delete self2[key];
|
|
1590
|
+
deleted = true;
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
if (utils$1.isArray(header)) {
|
|
1595
|
+
header.forEach(deleteHeader);
|
|
1596
|
+
} else {
|
|
1597
|
+
deleteHeader(header);
|
|
1598
|
+
}
|
|
1599
|
+
return deleted;
|
|
1600
|
+
}
|
|
1601
|
+
clear(matcher) {
|
|
1602
|
+
const keys = Object.keys(this);
|
|
1603
|
+
let i = keys.length;
|
|
1604
|
+
let deleted = false;
|
|
1605
|
+
while (i--) {
|
|
1606
|
+
const key = keys[i];
|
|
1607
|
+
if (!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
|
|
1608
|
+
delete this[key];
|
|
1609
|
+
deleted = true;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
return deleted;
|
|
1613
|
+
}
|
|
1614
|
+
normalize(format) {
|
|
1615
|
+
const self2 = this;
|
|
1616
|
+
const headers = {};
|
|
1617
|
+
utils$1.forEach(this, (value, header) => {
|
|
1618
|
+
const key = utils$1.findKey(headers, header);
|
|
1619
|
+
if (key) {
|
|
1620
|
+
self2[key] = normalizeValue(value);
|
|
1621
|
+
delete self2[header];
|
|
1622
|
+
return;
|
|
1623
|
+
}
|
|
1624
|
+
const normalized = format ? formatHeader(header) : String(header).trim();
|
|
1625
|
+
if (normalized !== header) {
|
|
1626
|
+
delete self2[header];
|
|
1627
|
+
}
|
|
1628
|
+
self2[normalized] = normalizeValue(value);
|
|
1629
|
+
headers[normalized] = true;
|
|
1630
|
+
});
|
|
1631
|
+
return this;
|
|
1632
|
+
}
|
|
1633
|
+
concat(...targets) {
|
|
1634
|
+
return this.constructor.concat(this, ...targets);
|
|
1635
|
+
}
|
|
1636
|
+
toJSON(asStrings) {
|
|
1637
|
+
const obj = /* @__PURE__ */ Object.create(null);
|
|
1638
|
+
utils$1.forEach(this, (value, header) => {
|
|
1639
|
+
value != null && value !== false && (obj[header] = asStrings && utils$1.isArray(value) ? value.join(", ") : value);
|
|
1640
|
+
});
|
|
1641
|
+
return obj;
|
|
1642
|
+
}
|
|
1643
|
+
[Symbol.iterator]() {
|
|
1644
|
+
return Object.entries(this.toJSON())[Symbol.iterator]();
|
|
1645
|
+
}
|
|
1646
|
+
toString() {
|
|
1647
|
+
return Object.entries(this.toJSON()).map(([header, value]) => header + ": " + value).join("\n");
|
|
1648
|
+
}
|
|
1649
|
+
getSetCookie() {
|
|
1650
|
+
return this.get("set-cookie") || [];
|
|
1651
|
+
}
|
|
1652
|
+
get [Symbol.toStringTag]() {
|
|
1653
|
+
return "AxiosHeaders";
|
|
1654
|
+
}
|
|
1655
|
+
static from(thing) {
|
|
1656
|
+
return thing instanceof this ? thing : new this(thing);
|
|
1657
|
+
}
|
|
1658
|
+
static concat(first, ...targets) {
|
|
1659
|
+
const computed = new this(first);
|
|
1660
|
+
targets.forEach((target) => computed.set(target));
|
|
1661
|
+
return computed;
|
|
1662
|
+
}
|
|
1663
|
+
static accessor(header) {
|
|
1664
|
+
const internals = this[$internals] = this[$internals] = {
|
|
1665
|
+
accessors: {}
|
|
1666
|
+
};
|
|
1667
|
+
const accessors = internals.accessors;
|
|
1668
|
+
const prototype2 = this.prototype;
|
|
1669
|
+
function defineAccessor(_header) {
|
|
1670
|
+
const lHeader = normalizeHeader(_header);
|
|
1671
|
+
if (!accessors[lHeader]) {
|
|
1672
|
+
buildAccessors(prototype2, _header);
|
|
1673
|
+
accessors[lHeader] = true;
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
utils$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
|
1677
|
+
return this;
|
|
1678
|
+
}
|
|
1679
|
+
};
|
|
1680
|
+
AxiosHeaders$1.accessor([
|
|
1681
|
+
"Content-Type",
|
|
1682
|
+
"Content-Length",
|
|
1683
|
+
"Accept",
|
|
1684
|
+
"Accept-Encoding",
|
|
1685
|
+
"User-Agent",
|
|
1686
|
+
"Authorization"
|
|
1687
|
+
]);
|
|
1688
|
+
utils$1.reduceDescriptors(AxiosHeaders$1.prototype, ({ value }, key) => {
|
|
1689
|
+
let mapped = key[0].toUpperCase() + key.slice(1);
|
|
1690
|
+
return {
|
|
1691
|
+
get: () => value,
|
|
1692
|
+
set(headerValue) {
|
|
1693
|
+
this[mapped] = headerValue;
|
|
1694
|
+
}
|
|
1695
|
+
};
|
|
1696
|
+
});
|
|
1697
|
+
utils$1.freezeMethods(AxiosHeaders$1);
|
|
1698
|
+
const REDACTED = "[REDACTED ****]";
|
|
1699
|
+
function hasOwnOrPrototypeToJSON(source) {
|
|
1700
|
+
if (utils$1.hasOwnProp(source, "toJSON")) {
|
|
1701
|
+
return true;
|
|
1702
|
+
}
|
|
1703
|
+
let prototype2 = Object.getPrototypeOf(source);
|
|
1704
|
+
while (prototype2 && prototype2 !== Object.prototype) {
|
|
1705
|
+
if (utils$1.hasOwnProp(prototype2, "toJSON")) {
|
|
1706
|
+
return true;
|
|
1707
|
+
}
|
|
1708
|
+
prototype2 = Object.getPrototypeOf(prototype2);
|
|
1709
|
+
}
|
|
1710
|
+
return false;
|
|
1711
|
+
}
|
|
1712
|
+
function redactConfig(config2, redactKeys) {
|
|
1713
|
+
const lowerKeys = new Set(redactKeys.map((k) => String(k).toLowerCase()));
|
|
1714
|
+
const seen = [];
|
|
1715
|
+
const visit = (source) => {
|
|
1716
|
+
if (source === null || typeof source !== "object") return source;
|
|
1717
|
+
if (utils$1.isBuffer(source)) return source;
|
|
1718
|
+
if (seen.indexOf(source) !== -1) return void 0;
|
|
1719
|
+
if (source instanceof AxiosHeaders$1) {
|
|
1720
|
+
source = source.toJSON();
|
|
1721
|
+
}
|
|
1722
|
+
seen.push(source);
|
|
1723
|
+
let result;
|
|
1724
|
+
if (utils$1.isArray(source)) {
|
|
1725
|
+
result = [];
|
|
1726
|
+
source.forEach((v, i) => {
|
|
1727
|
+
const reducedValue = visit(v);
|
|
1728
|
+
if (!utils$1.isUndefined(reducedValue)) {
|
|
1729
|
+
result[i] = reducedValue;
|
|
1730
|
+
}
|
|
1731
|
+
});
|
|
1732
|
+
} else {
|
|
1733
|
+
if (!utils$1.isPlainObject(source) && hasOwnOrPrototypeToJSON(source)) {
|
|
1734
|
+
seen.pop();
|
|
1735
|
+
return source;
|
|
1736
|
+
}
|
|
1737
|
+
result = /* @__PURE__ */ Object.create(null);
|
|
1738
|
+
for (const [key, value] of Object.entries(source)) {
|
|
1739
|
+
const reducedValue = lowerKeys.has(key.toLowerCase()) ? REDACTED : visit(value);
|
|
1740
|
+
if (!utils$1.isUndefined(reducedValue)) {
|
|
1741
|
+
result[key] = reducedValue;
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
seen.pop();
|
|
1746
|
+
return result;
|
|
1747
|
+
};
|
|
1748
|
+
return visit(config2);
|
|
1749
|
+
}
|
|
1750
|
+
let AxiosError$1 = class AxiosError extends Error {
|
|
1751
|
+
static from(error, code, config2, request, response, customProps) {
|
|
1752
|
+
const axiosError = new AxiosError(error.message, code || error.code, config2, request, response);
|
|
1753
|
+
Object.defineProperty(axiosError, "cause", {
|
|
1754
|
+
__proto__: null,
|
|
1755
|
+
value: error,
|
|
1756
|
+
writable: true,
|
|
1757
|
+
enumerable: false,
|
|
1758
|
+
configurable: true
|
|
1759
|
+
});
|
|
1760
|
+
axiosError.name = error.name;
|
|
1761
|
+
if (error.status != null && axiosError.status == null) {
|
|
1762
|
+
axiosError.status = error.status;
|
|
1763
|
+
}
|
|
1764
|
+
customProps && Object.assign(axiosError, customProps);
|
|
1765
|
+
return axiosError;
|
|
1766
|
+
}
|
|
1767
|
+
/**
|
|
1768
|
+
* Create an Error with the specified message, config, error code, request and response.
|
|
1769
|
+
*
|
|
1770
|
+
* @param {string} message The error message.
|
|
1771
|
+
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
|
1772
|
+
* @param {Object} [config] The config.
|
|
1773
|
+
* @param {Object} [request] The request.
|
|
1774
|
+
* @param {Object} [response] The response.
|
|
1775
|
+
*
|
|
1776
|
+
* @returns {Error} The created error.
|
|
1777
|
+
*/
|
|
1778
|
+
constructor(message, code, config2, request, response) {
|
|
1779
|
+
super(message);
|
|
1780
|
+
Object.defineProperty(this, "message", {
|
|
1781
|
+
// Null-proto descriptor so a polluted Object.prototype.get cannot turn
|
|
1782
|
+
// this data descriptor into an accessor descriptor on the way in.
|
|
1783
|
+
__proto__: null,
|
|
1784
|
+
value: message,
|
|
1785
|
+
enumerable: true,
|
|
1786
|
+
writable: true,
|
|
1787
|
+
configurable: true
|
|
1788
|
+
});
|
|
1789
|
+
this.name = "AxiosError";
|
|
1790
|
+
this.isAxiosError = true;
|
|
1791
|
+
code && (this.code = code);
|
|
1792
|
+
config2 && (this.config = config2);
|
|
1793
|
+
request && (this.request = request);
|
|
1794
|
+
if (response) {
|
|
1795
|
+
this.response = response;
|
|
1796
|
+
this.status = response.status;
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
toJSON() {
|
|
1800
|
+
const config2 = this.config;
|
|
1801
|
+
const redactKeys = config2 && utils$1.hasOwnProp(config2, "redact") ? config2.redact : void 0;
|
|
1802
|
+
const serializedConfig = utils$1.isArray(redactKeys) && redactKeys.length > 0 ? redactConfig(config2, redactKeys) : utils$1.toJSONObject(config2);
|
|
1803
|
+
return {
|
|
1804
|
+
// Standard
|
|
1805
|
+
message: this.message,
|
|
1806
|
+
name: this.name,
|
|
1807
|
+
// Microsoft
|
|
1808
|
+
description: this.description,
|
|
1809
|
+
number: this.number,
|
|
1810
|
+
// Mozilla
|
|
1811
|
+
fileName: this.fileName,
|
|
1812
|
+
lineNumber: this.lineNumber,
|
|
1813
|
+
columnNumber: this.columnNumber,
|
|
1814
|
+
stack: this.stack,
|
|
1815
|
+
// Axios
|
|
1816
|
+
config: serializedConfig,
|
|
1817
|
+
code: this.code,
|
|
1818
|
+
status: this.status
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
};
|
|
1822
|
+
AxiosError$1.ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
|
|
1823
|
+
AxiosError$1.ERR_BAD_OPTION = "ERR_BAD_OPTION";
|
|
1824
|
+
AxiosError$1.ECONNABORTED = "ECONNABORTED";
|
|
1825
|
+
AxiosError$1.ETIMEDOUT = "ETIMEDOUT";
|
|
1826
|
+
AxiosError$1.ECONNREFUSED = "ECONNREFUSED";
|
|
1827
|
+
AxiosError$1.ERR_NETWORK = "ERR_NETWORK";
|
|
1828
|
+
AxiosError$1.ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
|
|
1829
|
+
AxiosError$1.ERR_DEPRECATED = "ERR_DEPRECATED";
|
|
1830
|
+
AxiosError$1.ERR_BAD_RESPONSE = "ERR_BAD_RESPONSE";
|
|
1831
|
+
AxiosError$1.ERR_BAD_REQUEST = "ERR_BAD_REQUEST";
|
|
1832
|
+
AxiosError$1.ERR_CANCELED = "ERR_CANCELED";
|
|
1833
|
+
AxiosError$1.ERR_NOT_SUPPORT = "ERR_NOT_SUPPORT";
|
|
1834
|
+
AxiosError$1.ERR_INVALID_URL = "ERR_INVALID_URL";
|
|
1835
|
+
AxiosError$1.ERR_FORM_DATA_DEPTH_EXCEEDED = "ERR_FORM_DATA_DEPTH_EXCEEDED";
|
|
1836
|
+
const httpAdapter = null;
|
|
1837
|
+
const DEFAULT_FORM_DATA_MAX_DEPTH = 100;
|
|
1838
|
+
function isVisitable(thing) {
|
|
1839
|
+
return utils$1.isPlainObject(thing) || utils$1.isArray(thing);
|
|
1840
|
+
}
|
|
1841
|
+
function removeBrackets(key) {
|
|
1842
|
+
return utils$1.endsWith(key, "[]") ? key.slice(0, -2) : key;
|
|
1843
|
+
}
|
|
1844
|
+
function renderKey(path, key, dots) {
|
|
1845
|
+
if (!path) return key;
|
|
1846
|
+
return path.concat(key).map(function each(token, i) {
|
|
814
1847
|
token = removeBrackets(token);
|
|
815
1848
|
return !dots && i ? "[" + token + "]" : token;
|
|
816
1849
|
}).join(dots ? "." : "");
|
|
@@ -826,19 +1859,26 @@ function toFormData$1(obj, formData, options) {
|
|
|
826
1859
|
throw new TypeError("target must be an object");
|
|
827
1860
|
}
|
|
828
1861
|
formData = formData || new FormData();
|
|
829
|
-
options = utils$1.toFlatObject(
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
1862
|
+
options = utils$1.toFlatObject(
|
|
1863
|
+
options,
|
|
1864
|
+
{
|
|
1865
|
+
metaTokens: true,
|
|
1866
|
+
dots: false,
|
|
1867
|
+
indexes: false
|
|
1868
|
+
},
|
|
1869
|
+
false,
|
|
1870
|
+
function defined(option, source) {
|
|
1871
|
+
return !utils$1.isUndefined(source[option]);
|
|
1872
|
+
}
|
|
1873
|
+
);
|
|
836
1874
|
const metaTokens = options.metaTokens;
|
|
837
1875
|
const visitor = options.visitor || defaultVisitor;
|
|
838
1876
|
const dots = options.dots;
|
|
839
1877
|
const indexes = options.indexes;
|
|
840
1878
|
const _Blob = options.Blob || typeof Blob !== "undefined" && Blob;
|
|
1879
|
+
const maxDepth = options.maxDepth === void 0 ? DEFAULT_FORM_DATA_MAX_DEPTH : options.maxDepth;
|
|
841
1880
|
const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
|
|
1881
|
+
const stack = [];
|
|
842
1882
|
if (!utils$1.isFunction(visitor)) {
|
|
843
1883
|
throw new TypeError("visitor must be a function");
|
|
844
1884
|
}
|
|
@@ -854,16 +1894,51 @@ function toFormData$1(obj, formData, options) {
|
|
|
854
1894
|
throw new AxiosError$1("Blob is not supported. Use a Buffer instead.");
|
|
855
1895
|
}
|
|
856
1896
|
if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
|
|
857
|
-
|
|
1897
|
+
if (useBlob && typeof _Blob === "function") {
|
|
1898
|
+
return new _Blob([value]);
|
|
1899
|
+
}
|
|
1900
|
+
if (typeof Buffer !== "undefined") {
|
|
1901
|
+
return Buffer.from(value);
|
|
1902
|
+
}
|
|
1903
|
+
throw new AxiosError$1("Blob is not supported. Use a Buffer instead.", AxiosError$1.ERR_NOT_SUPPORT);
|
|
858
1904
|
}
|
|
859
1905
|
return value;
|
|
860
1906
|
}
|
|
1907
|
+
function throwIfMaxDepthExceeded(depth) {
|
|
1908
|
+
if (depth > maxDepth) {
|
|
1909
|
+
throw new AxiosError$1(
|
|
1910
|
+
"Object is too deeply nested (" + depth + " levels). Max depth: " + maxDepth,
|
|
1911
|
+
AxiosError$1.ERR_FORM_DATA_DEPTH_EXCEEDED
|
|
1912
|
+
);
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
function stringifyWithDepthLimit(value, depth) {
|
|
1916
|
+
if (maxDepth === Infinity) {
|
|
1917
|
+
return JSON.stringify(value);
|
|
1918
|
+
}
|
|
1919
|
+
const ancestors = [];
|
|
1920
|
+
return JSON.stringify(value, function limitDepth(_key, currentValue) {
|
|
1921
|
+
if (!utils$1.isObject(currentValue)) {
|
|
1922
|
+
return currentValue;
|
|
1923
|
+
}
|
|
1924
|
+
while (ancestors.length && ancestors[ancestors.length - 1] !== this) {
|
|
1925
|
+
ancestors.pop();
|
|
1926
|
+
}
|
|
1927
|
+
ancestors.push(currentValue);
|
|
1928
|
+
throwIfMaxDepthExceeded(depth + ancestors.length - 1);
|
|
1929
|
+
return currentValue;
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
861
1932
|
function defaultVisitor(value, key, path) {
|
|
862
1933
|
let arr = value;
|
|
1934
|
+
if (utils$1.isReactNative(formData) && utils$1.isReactNativeBlob(value)) {
|
|
1935
|
+
formData.append(renderKey(path, key, dots), convertValue(value));
|
|
1936
|
+
return false;
|
|
1937
|
+
}
|
|
863
1938
|
if (value && !path && typeof value === "object") {
|
|
864
1939
|
if (utils$1.endsWith(key, "{}")) {
|
|
865
1940
|
key = metaTokens ? key : key.slice(0, -2);
|
|
866
|
-
value =
|
|
1941
|
+
value = stringifyWithDepthLimit(value, 1);
|
|
867
1942
|
} else if (utils$1.isArray(value) && isFlatArray(value) || (utils$1.isFileList(value) || utils$1.endsWith(key, "[]")) && (arr = utils$1.toArray(value))) {
|
|
868
1943
|
key = removeBrackets(key);
|
|
869
1944
|
arr.forEach(function each(el, index2) {
|
|
@@ -882,28 +1957,22 @@ function toFormData$1(obj, formData, options) {
|
|
|
882
1957
|
formData.append(renderKey(path, key, dots), convertValue(value));
|
|
883
1958
|
return false;
|
|
884
1959
|
}
|
|
885
|
-
const stack = [];
|
|
886
1960
|
const exposedHelpers = Object.assign(predicates, {
|
|
887
1961
|
defaultVisitor,
|
|
888
1962
|
convertValue,
|
|
889
1963
|
isVisitable
|
|
890
1964
|
});
|
|
891
|
-
function build(value, path) {
|
|
1965
|
+
function build(value, path, depth = 0) {
|
|
892
1966
|
if (utils$1.isUndefined(value)) return;
|
|
1967
|
+
throwIfMaxDepthExceeded(depth);
|
|
893
1968
|
if (stack.indexOf(value) !== -1) {
|
|
894
|
-
throw Error("Circular reference detected in " + path.join("."));
|
|
1969
|
+
throw new Error("Circular reference detected in " + path.join("."));
|
|
895
1970
|
}
|
|
896
1971
|
stack.push(value);
|
|
897
1972
|
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
|
-
);
|
|
1973
|
+
const result = !(utils$1.isUndefined(el) || el === null) && visitor.call(formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers);
|
|
905
1974
|
if (result === true) {
|
|
906
|
-
build(el, path ? path.concat(key) : [key]);
|
|
1975
|
+
build(el, path ? path.concat(key) : [key], depth + 1);
|
|
907
1976
|
}
|
|
908
1977
|
});
|
|
909
1978
|
stack.pop();
|
|
@@ -914,17 +1983,16 @@ function toFormData$1(obj, formData, options) {
|
|
|
914
1983
|
build(obj);
|
|
915
1984
|
return formData;
|
|
916
1985
|
}
|
|
917
|
-
function encode$1(
|
|
1986
|
+
function encode$1(str2) {
|
|
918
1987
|
const charMap = {
|
|
919
1988
|
"!": "%21",
|
|
920
1989
|
"'": "%27",
|
|
921
1990
|
"(": "%28",
|
|
922
1991
|
")": "%29",
|
|
923
1992
|
"~": "%7E",
|
|
924
|
-
"%20": "+"
|
|
925
|
-
"%00": "\0"
|
|
1993
|
+
"%20": "+"
|
|
926
1994
|
};
|
|
927
|
-
return encodeURIComponent(
|
|
1995
|
+
return encodeURIComponent(str2).replace(/[!'()~]|%20/g, function replacer(match) {
|
|
928
1996
|
return charMap[match];
|
|
929
1997
|
});
|
|
930
1998
|
}
|
|
@@ -933,13 +2001,11 @@ function AxiosURLSearchParams(params, options) {
|
|
|
933
2001
|
params && toFormData$1(params, this, options);
|
|
934
2002
|
}
|
|
935
2003
|
const prototype = AxiosURLSearchParams.prototype;
|
|
936
|
-
prototype.append = function append(
|
|
937
|
-
this._pairs.push([
|
|
2004
|
+
prototype.append = function append(name2, value) {
|
|
2005
|
+
this._pairs.push([name2, value]);
|
|
938
2006
|
};
|
|
939
2007
|
prototype.toString = function toString2(encoder) {
|
|
940
|
-
const _encode = encoder ?
|
|
941
|
-
return encoder.call(this, value, encode$1);
|
|
942
|
-
} : encode$1;
|
|
2008
|
+
const _encode = encoder ? (value) => encoder.call(this, value, encode$1) : encode$1;
|
|
943
2009
|
return this._pairs.map(function each(pair) {
|
|
944
2010
|
return _encode(pair[0]) + "=" + _encode(pair[1]);
|
|
945
2011
|
}, "").join("&");
|
|
@@ -951,18 +2017,17 @@ function buildURL(url, params, options) {
|
|
|
951
2017
|
if (!params) {
|
|
952
2018
|
return url;
|
|
953
2019
|
}
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
options
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
const serializeFn = options && options.serialize;
|
|
2020
|
+
url = url || "";
|
|
2021
|
+
const _options = utils$1.isFunction(options) ? {
|
|
2022
|
+
serialize: options
|
|
2023
|
+
} : options;
|
|
2024
|
+
const _encode = utils$1.getSafeProp(_options, "encode") || encode;
|
|
2025
|
+
const serializeFn = utils$1.getSafeProp(_options, "serialize");
|
|
961
2026
|
let serializedParams;
|
|
962
2027
|
if (serializeFn) {
|
|
963
|
-
serializedParams = serializeFn(params,
|
|
2028
|
+
serializedParams = serializeFn(params, _options);
|
|
964
2029
|
} else {
|
|
965
|
-
serializedParams = utils$1.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params,
|
|
2030
|
+
serializedParams = utils$1.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params, _options).toString(_encode);
|
|
966
2031
|
}
|
|
967
2032
|
if (serializedParams) {
|
|
968
2033
|
const hashmarkIndex = url.indexOf("#");
|
|
@@ -982,6 +2047,7 @@ class InterceptorManager {
|
|
|
982
2047
|
*
|
|
983
2048
|
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
|
984
2049
|
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
|
2050
|
+
* @param {Object} options The options for the interceptor, synchronous and runWhen
|
|
985
2051
|
*
|
|
986
2052
|
* @return {Number} An ID used to remove interceptor later
|
|
987
2053
|
*/
|
|
@@ -999,7 +2065,7 @@ class InterceptorManager {
|
|
|
999
2065
|
*
|
|
1000
2066
|
* @param {Number} id The ID that was returned by `use`
|
|
1001
2067
|
*
|
|
1002
|
-
* @returns {
|
|
2068
|
+
* @returns {void}
|
|
1003
2069
|
*/
|
|
1004
2070
|
eject(id) {
|
|
1005
2071
|
if (this.handlers[id]) {
|
|
@@ -1037,7 +2103,10 @@ class InterceptorManager {
|
|
|
1037
2103
|
const transitionalDefaults = {
|
|
1038
2104
|
silentJSONParsing: true,
|
|
1039
2105
|
forcedJSONParsing: true,
|
|
1040
|
-
clarifyTimeoutError: false
|
|
2106
|
+
clarifyTimeoutError: false,
|
|
2107
|
+
legacyInterceptorReqResOrdering: true,
|
|
2108
|
+
advertiseZstdAcceptEncoding: false,
|
|
2109
|
+
validateStatusUndefinedResolves: true
|
|
1041
2110
|
};
|
|
1042
2111
|
const URLSearchParams$1 = typeof URLSearchParams !== "undefined" ? URLSearchParams : AxiosURLSearchParams;
|
|
1043
2112
|
const FormData$1 = typeof FormData !== "undefined" ? FormData : null;
|
|
@@ -1071,443 +2140,197 @@ const platform = {
|
|
|
1071
2140
|
...utils,
|
|
1072
2141
|
...platform$1
|
|
1073
2142
|
};
|
|
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];
|
|
2143
|
+
function toURLEncodedForm(data, options) {
|
|
2144
|
+
return toFormData$1(data, new platform.classes.URLSearchParams(), {
|
|
2145
|
+
visitor: function(value, key, path, helpers) {
|
|
2146
|
+
if (platform.isNode && utils$1.isBuffer(value)) {
|
|
2147
|
+
this.append(key, value.toString("base64"));
|
|
2148
|
+
return false;
|
|
1364
2149
|
}
|
|
1365
|
-
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
2150
|
+
return helpers.defaultVisitor.apply(this, arguments);
|
|
2151
|
+
},
|
|
2152
|
+
...options
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2155
|
+
const MAX_DEPTH = DEFAULT_FORM_DATA_MAX_DEPTH;
|
|
2156
|
+
function throwIfDepthExceeded(index2) {
|
|
2157
|
+
if (index2 > MAX_DEPTH) {
|
|
2158
|
+
throw new AxiosError$1(
|
|
2159
|
+
"FormData field is too deeply nested (" + index2 + " levels). Max depth: " + MAX_DEPTH,
|
|
2160
|
+
AxiosError$1.ERR_FORM_DATA_DEPTH_EXCEEDED
|
|
2161
|
+
);
|
|
1370
2162
|
}
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
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");
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
2163
|
+
}
|
|
2164
|
+
function parsePropPath(name2) {
|
|
2165
|
+
const path = [];
|
|
2166
|
+
const pattern = /\w+|\[(\w*)]/g;
|
|
2167
|
+
let match;
|
|
2168
|
+
while ((match = pattern.exec(name2)) !== null) {
|
|
2169
|
+
throwIfDepthExceeded(path.length);
|
|
2170
|
+
path.push(match[0] === "[]" ? "" : match[1] || match[0]);
|
|
1392
2171
|
}
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
2172
|
+
return path;
|
|
2173
|
+
}
|
|
2174
|
+
function arrayToObject(arr) {
|
|
2175
|
+
const obj = {};
|
|
2176
|
+
const keys = Object.keys(arr);
|
|
2177
|
+
let i;
|
|
2178
|
+
const len = keys.length;
|
|
2179
|
+
let key;
|
|
2180
|
+
for (i = 0; i < len; i++) {
|
|
2181
|
+
key = keys[i];
|
|
2182
|
+
obj[key] = arr[key];
|
|
1400
2183
|
}
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
2184
|
+
return obj;
|
|
2185
|
+
}
|
|
2186
|
+
function formDataToJSON(formData) {
|
|
2187
|
+
function buildPath(path, value, target, index2) {
|
|
2188
|
+
throwIfDepthExceeded(index2);
|
|
2189
|
+
let name2 = path[index2++];
|
|
2190
|
+
if (name2 === "__proto__") return true;
|
|
2191
|
+
const isNumericKey = Number.isFinite(+name2);
|
|
2192
|
+
const isLast = index2 >= path.length;
|
|
2193
|
+
name2 = !name2 && utils$1.isArray(target) ? target.length : name2;
|
|
2194
|
+
if (isLast) {
|
|
2195
|
+
if (utils$1.hasOwnProp(target, name2)) {
|
|
2196
|
+
target[name2] = utils$1.isArray(target[name2]) ? target[name2].concat(value) : [target[name2], value];
|
|
2197
|
+
} else {
|
|
2198
|
+
target[name2] = value;
|
|
1412
2199
|
}
|
|
2200
|
+
return !isNumericKey;
|
|
1413
2201
|
}
|
|
1414
|
-
if (utils$1.
|
|
1415
|
-
|
|
1416
|
-
} else {
|
|
1417
|
-
deleteHeader(header);
|
|
2202
|
+
if (!utils$1.hasOwnProp(target, name2) || !utils$1.isObject(target[name2])) {
|
|
2203
|
+
target[name2] = [];
|
|
1418
2204
|
}
|
|
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
|
-
}
|
|
2205
|
+
const result = buildPath(path, value, target[name2], index2);
|
|
2206
|
+
if (result && utils$1.isArray(target[name2])) {
|
|
2207
|
+
target[name2] = arrayToObject(target[name2]);
|
|
1431
2208
|
}
|
|
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);
|
|
2209
|
+
return !isNumericKey;
|
|
1455
2210
|
}
|
|
1456
|
-
|
|
1457
|
-
const obj =
|
|
1458
|
-
utils$1.
|
|
1459
|
-
|
|
2211
|
+
if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
|
|
2212
|
+
const obj = {};
|
|
2213
|
+
utils$1.forEachEntry(formData, (name2, value) => {
|
|
2214
|
+
buildPath(parsePropPath(name2), value, obj, 0);
|
|
1460
2215
|
});
|
|
1461
2216
|
return obj;
|
|
1462
2217
|
}
|
|
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;
|
|
2218
|
+
return null;
|
|
2219
|
+
}
|
|
2220
|
+
const own = (obj, key) => obj != null && utils$1.hasOwnProp(obj, key) ? obj[key] : void 0;
|
|
2221
|
+
function stringifySafely(rawValue, parser, encoder) {
|
|
2222
|
+
if (utils$1.isString(rawValue)) {
|
|
2223
|
+
try {
|
|
2224
|
+
(parser || JSON.parse)(rawValue);
|
|
2225
|
+
return utils$1.trim(rawValue);
|
|
2226
|
+
} catch (e) {
|
|
2227
|
+
if (e.name !== "SyntaxError") {
|
|
2228
|
+
throw e;
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
1482
2231
|
}
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
function
|
|
1490
|
-
const
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
2232
|
+
return (encoder || JSON.stringify)(rawValue);
|
|
2233
|
+
}
|
|
2234
|
+
const defaults = {
|
|
2235
|
+
transitional: transitionalDefaults,
|
|
2236
|
+
adapter: ["xhr", "http", "fetch"],
|
|
2237
|
+
transformRequest: [
|
|
2238
|
+
function transformRequest(data, headers) {
|
|
2239
|
+
const contentType = headers.getContentType() || "";
|
|
2240
|
+
const hasJSONContentType = contentType.indexOf("application/json") > -1;
|
|
2241
|
+
const isObjectPayload = utils$1.isObject(data);
|
|
2242
|
+
if (isObjectPayload && utils$1.isHTMLForm(data)) {
|
|
2243
|
+
data = new FormData(data);
|
|
2244
|
+
}
|
|
2245
|
+
const isFormData2 = utils$1.isFormData(data);
|
|
2246
|
+
if (isFormData2) {
|
|
2247
|
+
return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
|
|
2248
|
+
}
|
|
2249
|
+
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)) {
|
|
2250
|
+
return data;
|
|
2251
|
+
}
|
|
2252
|
+
if (utils$1.isArrayBufferView(data)) {
|
|
2253
|
+
return data.buffer;
|
|
2254
|
+
}
|
|
2255
|
+
if (utils$1.isURLSearchParams(data)) {
|
|
2256
|
+
headers.setContentType("application/x-www-form-urlencoded;charset=utf-8", false);
|
|
2257
|
+
return data.toString();
|
|
2258
|
+
}
|
|
2259
|
+
let isFileList2;
|
|
2260
|
+
if (isObjectPayload) {
|
|
2261
|
+
const formSerializer = own(this, "formSerializer");
|
|
2262
|
+
if (contentType.indexOf("application/x-www-form-urlencoded") > -1) {
|
|
2263
|
+
return toURLEncodedForm(data, formSerializer).toString();
|
|
2264
|
+
}
|
|
2265
|
+
if ((isFileList2 = utils$1.isFileList(data)) || contentType.indexOf("multipart/form-data") > -1) {
|
|
2266
|
+
const env = own(this, "env");
|
|
2267
|
+
const _FormData = env && env.FormData;
|
|
2268
|
+
return toFormData$1(
|
|
2269
|
+
isFileList2 ? { "files[]": data } : data,
|
|
2270
|
+
_FormData && new _FormData(),
|
|
2271
|
+
formSerializer
|
|
2272
|
+
);
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
if (isObjectPayload || hasJSONContentType) {
|
|
2276
|
+
headers.setContentType("application/json", false);
|
|
2277
|
+
return stringifySafely(data);
|
|
1494
2278
|
}
|
|
2279
|
+
return data;
|
|
2280
|
+
}
|
|
2281
|
+
],
|
|
2282
|
+
transformResponse: [
|
|
2283
|
+
function transformResponse(data) {
|
|
2284
|
+
const transitional2 = own(this, "transitional") || defaults.transitional;
|
|
2285
|
+
const forcedJSONParsing = transitional2 && transitional2.forcedJSONParsing;
|
|
2286
|
+
const responseType = own(this, "responseType");
|
|
2287
|
+
const JSONRequested = responseType === "json";
|
|
2288
|
+
if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
|
|
2289
|
+
return data;
|
|
2290
|
+
}
|
|
2291
|
+
if (data && utils$1.isString(data) && (forcedJSONParsing && !responseType || JSONRequested)) {
|
|
2292
|
+
const silentJSONParsing = transitional2 && transitional2.silentJSONParsing;
|
|
2293
|
+
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
|
2294
|
+
try {
|
|
2295
|
+
return JSON.parse(data, own(this, "parseReviver"));
|
|
2296
|
+
} catch (e) {
|
|
2297
|
+
if (strictJSONParsing) {
|
|
2298
|
+
if (e.name === "SyntaxError") {
|
|
2299
|
+
throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_RESPONSE, this, null, own(this, "response"));
|
|
2300
|
+
}
|
|
2301
|
+
throw e;
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
return data;
|
|
2306
|
+
}
|
|
2307
|
+
],
|
|
2308
|
+
/**
|
|
2309
|
+
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
|
2310
|
+
* timeout is not created.
|
|
2311
|
+
*/
|
|
2312
|
+
timeout: 0,
|
|
2313
|
+
xsrfCookieName: "XSRF-TOKEN",
|
|
2314
|
+
xsrfHeaderName: "X-XSRF-TOKEN",
|
|
2315
|
+
maxContentLength: -1,
|
|
2316
|
+
maxBodyLength: -1,
|
|
2317
|
+
env: {
|
|
2318
|
+
FormData: platform.classes.FormData,
|
|
2319
|
+
Blob: platform.classes.Blob
|
|
2320
|
+
},
|
|
2321
|
+
validateStatus: function validateStatus(status) {
|
|
2322
|
+
return status >= 200 && status < 300;
|
|
2323
|
+
},
|
|
2324
|
+
headers: {
|
|
2325
|
+
common: {
|
|
2326
|
+
Accept: "application/json, text/plain, */*",
|
|
2327
|
+
"Content-Type": void 0
|
|
1495
2328
|
}
|
|
1496
|
-
utils$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
|
1497
|
-
return this;
|
|
1498
2329
|
}
|
|
1499
2330
|
};
|
|
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
|
-
};
|
|
2331
|
+
utils$1.forEach(["delete", "get", "head", "post", "put", "patch", "query"], (method) => {
|
|
2332
|
+
defaults.headers[method] = {};
|
|
1509
2333
|
});
|
|
1510
|
-
utils$1.freezeMethods(AxiosHeaders$1);
|
|
1511
2334
|
function transformData(fns, response) {
|
|
1512
2335
|
const config2 = this || defaults;
|
|
1513
2336
|
const context = response || config2;
|
|
@@ -1522,13 +2345,22 @@ function transformData(fns, response) {
|
|
|
1522
2345
|
function isCancel$1(value) {
|
|
1523
2346
|
return !!(value && value.__CANCEL__);
|
|
1524
2347
|
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
}
|
|
2348
|
+
let CanceledError$1 = class CanceledError extends AxiosError$1 {
|
|
2349
|
+
/**
|
|
2350
|
+
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
|
2351
|
+
*
|
|
2352
|
+
* @param {string=} message The message.
|
|
2353
|
+
* @param {Object=} config The config.
|
|
2354
|
+
* @param {Object=} request The request.
|
|
2355
|
+
*
|
|
2356
|
+
* @returns {CanceledError} The created error.
|
|
2357
|
+
*/
|
|
2358
|
+
constructor(message, config2, request) {
|
|
2359
|
+
super(message == null ? "canceled" : message, AxiosError$1.ERR_CANCELED, config2, request);
|
|
2360
|
+
this.name = "CanceledError";
|
|
2361
|
+
this.__CANCEL__ = true;
|
|
2362
|
+
}
|
|
2363
|
+
};
|
|
1532
2364
|
function settle(resolve, reject, response) {
|
|
1533
2365
|
const validateStatus2 = response.config.validateStatus;
|
|
1534
2366
|
if (!response.status || !validateStatus2 || validateStatus2(response.status)) {
|
|
@@ -1536,7 +2368,7 @@ function settle(resolve, reject, response) {
|
|
|
1536
2368
|
} else {
|
|
1537
2369
|
reject(new AxiosError$1(
|
|
1538
2370
|
"Request failed with status code " + response.status,
|
|
1539
|
-
|
|
2371
|
+
response.status >= 400 && response.status < 500 ? AxiosError$1.ERR_BAD_REQUEST : AxiosError$1.ERR_BAD_RESPONSE,
|
|
1540
2372
|
response.config,
|
|
1541
2373
|
response.request,
|
|
1542
2374
|
response
|
|
@@ -1544,7 +2376,7 @@ function settle(resolve, reject, response) {
|
|
|
1544
2376
|
}
|
|
1545
2377
|
}
|
|
1546
2378
|
function parseProtocol(url) {
|
|
1547
|
-
const match = /^([-+\w]{1,25})(
|
|
2379
|
+
const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url);
|
|
1548
2380
|
return match && match[1] || "";
|
|
1549
2381
|
}
|
|
1550
2382
|
function speedometer(samplesCount, min) {
|
|
@@ -1616,19 +2448,22 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
|
|
1616
2448
|
let bytesNotified = 0;
|
|
1617
2449
|
const _speedometer = speedometer(50, 250);
|
|
1618
2450
|
return throttle((e) => {
|
|
1619
|
-
|
|
2451
|
+
if (!e || typeof e.loaded !== "number") {
|
|
2452
|
+
return;
|
|
2453
|
+
}
|
|
2454
|
+
const rawLoaded = e.loaded;
|
|
1620
2455
|
const total = e.lengthComputable ? e.total : void 0;
|
|
1621
|
-
const
|
|
2456
|
+
const loaded = total != null ? Math.min(rawLoaded, total) : rawLoaded;
|
|
2457
|
+
const progressBytes = Math.max(0, loaded - bytesNotified);
|
|
1622
2458
|
const rate = _speedometer(progressBytes);
|
|
1623
|
-
|
|
1624
|
-
bytesNotified = loaded;
|
|
2459
|
+
bytesNotified = Math.max(bytesNotified, loaded);
|
|
1625
2460
|
const data = {
|
|
1626
2461
|
loaded,
|
|
1627
2462
|
total,
|
|
1628
2463
|
progress: total ? loaded / total : void 0,
|
|
1629
2464
|
bytes: progressBytes,
|
|
1630
2465
|
rate: rate ? rate : void 0,
|
|
1631
|
-
estimated: rate && total
|
|
2466
|
+
estimated: rate && total ? (total - loaded) / rate : void 0,
|
|
1632
2467
|
event: e,
|
|
1633
2468
|
lengthComputable: total != null,
|
|
1634
2469
|
[isDownloadStream ? "download" : "upload"]: true
|
|
@@ -1638,11 +2473,14 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
|
|
1638
2473
|
};
|
|
1639
2474
|
const progressEventDecorator = (total, throttled) => {
|
|
1640
2475
|
const lengthComputable = total != null;
|
|
1641
|
-
return [
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
2476
|
+
return [
|
|
2477
|
+
(loaded) => throttled[0]({
|
|
2478
|
+
lengthComputable,
|
|
2479
|
+
total,
|
|
2480
|
+
loaded
|
|
2481
|
+
}),
|
|
2482
|
+
throttled[1]
|
|
2483
|
+
];
|
|
1646
2484
|
};
|
|
1647
2485
|
const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
|
|
1648
2486
|
const isURLSameOrigin = platform.hasStandardBrowserEnv ? /* @__PURE__ */ ((origin2, isMSIE) => (url) => {
|
|
@@ -1655,20 +2493,44 @@ const isURLSameOrigin = platform.hasStandardBrowserEnv ? /* @__PURE__ */ ((origi
|
|
|
1655
2493
|
const cookies = platform.hasStandardBrowserEnv ? (
|
|
1656
2494
|
// Standard browser envs support document.cookie
|
|
1657
2495
|
{
|
|
1658
|
-
write(
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
utils$1.
|
|
1662
|
-
|
|
1663
|
-
|
|
2496
|
+
write(name2, value, expires, path, domain, secure, sameSite) {
|
|
2497
|
+
if (typeof document === "undefined") return;
|
|
2498
|
+
const cookie = [`${name2}=${encodeURIComponent(value)}`];
|
|
2499
|
+
if (utils$1.isNumber(expires)) {
|
|
2500
|
+
cookie.push(`expires=${new Date(expires).toUTCString()}`);
|
|
2501
|
+
}
|
|
2502
|
+
if (utils$1.isString(path)) {
|
|
2503
|
+
cookie.push(`path=${path}`);
|
|
2504
|
+
}
|
|
2505
|
+
if (utils$1.isString(domain)) {
|
|
2506
|
+
cookie.push(`domain=${domain}`);
|
|
2507
|
+
}
|
|
2508
|
+
if (secure === true) {
|
|
2509
|
+
cookie.push("secure");
|
|
2510
|
+
}
|
|
2511
|
+
if (utils$1.isString(sameSite)) {
|
|
2512
|
+
cookie.push(`SameSite=${sameSite}`);
|
|
2513
|
+
}
|
|
1664
2514
|
document.cookie = cookie.join("; ");
|
|
1665
2515
|
},
|
|
1666
|
-
read(
|
|
1667
|
-
|
|
1668
|
-
|
|
2516
|
+
read(name2) {
|
|
2517
|
+
if (typeof document === "undefined") return null;
|
|
2518
|
+
const cookies2 = document.cookie.split(";");
|
|
2519
|
+
for (let i = 0; i < cookies2.length; i++) {
|
|
2520
|
+
const cookie = cookies2[i].replace(/^\s+/, "");
|
|
2521
|
+
const eq = cookie.indexOf("=");
|
|
2522
|
+
if (eq !== -1 && cookie.slice(0, eq) === name2) {
|
|
2523
|
+
try {
|
|
2524
|
+
return decodeURIComponent(cookie.slice(eq + 1));
|
|
2525
|
+
} catch (e) {
|
|
2526
|
+
return cookie.slice(eq + 1);
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
return null;
|
|
1669
2531
|
},
|
|
1670
|
-
remove(
|
|
1671
|
-
this.write(
|
|
2532
|
+
remove(name2) {
|
|
2533
|
+
this.write(name2, "", Date.now() - 864e5, "/");
|
|
1672
2534
|
}
|
|
1673
2535
|
}
|
|
1674
2536
|
) : (
|
|
@@ -1684,22 +2546,58 @@ const cookies = platform.hasStandardBrowserEnv ? (
|
|
|
1684
2546
|
}
|
|
1685
2547
|
);
|
|
1686
2548
|
function isAbsoluteURL(url) {
|
|
2549
|
+
if (typeof url !== "string") {
|
|
2550
|
+
return false;
|
|
2551
|
+
}
|
|
1687
2552
|
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
|
1688
2553
|
}
|
|
1689
2554
|
function combineURLs(baseURL, relativeURL) {
|
|
1690
2555
|
return relativeURL ? baseURL.replace(/\/?\/$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
|
|
1691
2556
|
}
|
|
1692
|
-
|
|
2557
|
+
const malformedHttpProtocol = /^https?:(?!\/\/)/i;
|
|
2558
|
+
const httpProtocolControlCharacters = /[\t\n\r]/g;
|
|
2559
|
+
function stripLeadingC0ControlOrSpace(url) {
|
|
2560
|
+
let i = 0;
|
|
2561
|
+
while (i < url.length && url.charCodeAt(i) <= 32) {
|
|
2562
|
+
i++;
|
|
2563
|
+
}
|
|
2564
|
+
return url.slice(i);
|
|
2565
|
+
}
|
|
2566
|
+
function normalizeURLForProtocolCheck(url) {
|
|
2567
|
+
return stripLeadingC0ControlOrSpace(url).replace(httpProtocolControlCharacters, "");
|
|
2568
|
+
}
|
|
2569
|
+
function assertValidHttpProtocolURL(url, config2) {
|
|
2570
|
+
if (typeof url === "string" && malformedHttpProtocol.test(normalizeURLForProtocolCheck(url))) {
|
|
2571
|
+
throw new AxiosError$1(
|
|
2572
|
+
'Invalid URL: missing "//" after protocol',
|
|
2573
|
+
AxiosError$1.ERR_INVALID_URL,
|
|
2574
|
+
config2
|
|
2575
|
+
);
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls, config2) {
|
|
2579
|
+
assertValidHttpProtocolURL(requestedURL, config2);
|
|
1693
2580
|
let isRelativeUrl = !isAbsoluteURL(requestedURL);
|
|
1694
|
-
if (baseURL && (isRelativeUrl || allowAbsoluteUrls
|
|
2581
|
+
if (baseURL && (isRelativeUrl || allowAbsoluteUrls === false)) {
|
|
2582
|
+
assertValidHttpProtocolURL(baseURL, config2);
|
|
1695
2583
|
return combineURLs(baseURL, requestedURL);
|
|
1696
2584
|
}
|
|
1697
2585
|
return requestedURL;
|
|
1698
2586
|
}
|
|
1699
2587
|
const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? { ...thing } : thing;
|
|
1700
2588
|
function mergeConfig$1(config1, config2) {
|
|
2589
|
+
config1 = config1 || {};
|
|
1701
2590
|
config2 = config2 || {};
|
|
1702
|
-
const config3 =
|
|
2591
|
+
const config3 = /* @__PURE__ */ Object.create(null);
|
|
2592
|
+
Object.defineProperty(config3, "hasOwnProperty", {
|
|
2593
|
+
// Null-proto descriptor so a polluted Object.prototype.get cannot turn
|
|
2594
|
+
// this data descriptor into an accessor descriptor on the way in.
|
|
2595
|
+
__proto__: null,
|
|
2596
|
+
value: Object.prototype.hasOwnProperty,
|
|
2597
|
+
enumerable: false,
|
|
2598
|
+
writable: true,
|
|
2599
|
+
configurable: true
|
|
2600
|
+
});
|
|
1703
2601
|
function getMergedValue(target, source, prop, caseless) {
|
|
1704
2602
|
if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
|
|
1705
2603
|
return utils$1.merge.call({ caseless }, target, source);
|
|
@@ -1729,10 +2627,27 @@ function mergeConfig$1(config1, config2) {
|
|
|
1729
2627
|
return getMergedValue(void 0, a);
|
|
1730
2628
|
}
|
|
1731
2629
|
}
|
|
2630
|
+
function getMergedTransitionalOption(prop) {
|
|
2631
|
+
const transitional2 = utils$1.hasOwnProp(config2, "transitional") ? config2.transitional : void 0;
|
|
2632
|
+
if (!utils$1.isUndefined(transitional2)) {
|
|
2633
|
+
if (utils$1.isPlainObject(transitional2)) {
|
|
2634
|
+
if (utils$1.hasOwnProp(transitional2, prop)) {
|
|
2635
|
+
return transitional2[prop];
|
|
2636
|
+
}
|
|
2637
|
+
} else {
|
|
2638
|
+
return void 0;
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
const transitional1 = utils$1.hasOwnProp(config1, "transitional") ? config1.transitional : void 0;
|
|
2642
|
+
if (utils$1.isPlainObject(transitional1) && utils$1.hasOwnProp(transitional1, prop)) {
|
|
2643
|
+
return transitional1[prop];
|
|
2644
|
+
}
|
|
2645
|
+
return void 0;
|
|
2646
|
+
}
|
|
1732
2647
|
function mergeDirectKeys(a, b, prop) {
|
|
1733
|
-
if (prop
|
|
2648
|
+
if (utils$1.hasOwnProp(config2, prop)) {
|
|
1734
2649
|
return getMergedValue(a, b);
|
|
1735
|
-
} else if (prop
|
|
2650
|
+
} else if (utils$1.hasOwnProp(config1, prop)) {
|
|
1736
2651
|
return getMergedValue(void 0, a);
|
|
1737
2652
|
}
|
|
1738
2653
|
}
|
|
@@ -1763,44 +2678,87 @@ function mergeConfig$1(config1, config2) {
|
|
|
1763
2678
|
httpsAgent: defaultToConfig2,
|
|
1764
2679
|
cancelToken: defaultToConfig2,
|
|
1765
2680
|
socketPath: defaultToConfig2,
|
|
2681
|
+
allowedSocketPaths: defaultToConfig2,
|
|
1766
2682
|
responseEncoding: defaultToConfig2,
|
|
1767
2683
|
validateStatus: mergeDirectKeys,
|
|
1768
2684
|
headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
|
|
1769
2685
|
};
|
|
1770
2686
|
utils$1.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
|
|
1771
|
-
|
|
1772
|
-
const
|
|
2687
|
+
if (prop === "__proto__" || prop === "constructor" || prop === "prototype") return;
|
|
2688
|
+
const merge2 = utils$1.hasOwnProp(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties;
|
|
2689
|
+
const a = utils$1.hasOwnProp(config1, prop) ? config1[prop] : void 0;
|
|
2690
|
+
const b = utils$1.hasOwnProp(config2, prop) ? config2[prop] : void 0;
|
|
2691
|
+
const configValue = merge2(a, b, prop);
|
|
1773
2692
|
utils$1.isUndefined(configValue) && merge2 !== mergeDirectKeys || (config3[prop] = configValue);
|
|
1774
2693
|
});
|
|
2694
|
+
if (utils$1.hasOwnProp(config2, "validateStatus") && utils$1.isUndefined(config2.validateStatus) && getMergedTransitionalOption("validateStatusUndefinedResolves") === false) {
|
|
2695
|
+
if (utils$1.hasOwnProp(config1, "validateStatus")) {
|
|
2696
|
+
config3.validateStatus = getMergedValue(void 0, config1.validateStatus);
|
|
2697
|
+
} else {
|
|
2698
|
+
delete config3.validateStatus;
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
1775
2701
|
return config3;
|
|
1776
2702
|
}
|
|
1777
|
-
const
|
|
2703
|
+
const FORM_DATA_CONTENT_HEADERS = ["content-type", "content-length"];
|
|
2704
|
+
function setFormDataHeaders(headers, formHeaders, policy) {
|
|
2705
|
+
if (policy !== "content-only") {
|
|
2706
|
+
headers.set(formHeaders);
|
|
2707
|
+
return;
|
|
2708
|
+
}
|
|
2709
|
+
Object.entries(formHeaders || {}).forEach(([key, val]) => {
|
|
2710
|
+
if (FORM_DATA_CONTENT_HEADERS.includes(key.toLowerCase())) {
|
|
2711
|
+
headers.set(key, val);
|
|
2712
|
+
}
|
|
2713
|
+
});
|
|
2714
|
+
}
|
|
2715
|
+
const encodeUTF8$1 = (str2) => encodeURIComponent(str2).replace(
|
|
2716
|
+
/%([0-9A-F]{2})/gi,
|
|
2717
|
+
(_, hex) => String.fromCharCode(parseInt(hex, 16))
|
|
2718
|
+
);
|
|
2719
|
+
function resolveConfig(config2) {
|
|
1778
2720
|
const newConfig = mergeConfig$1({}, config2);
|
|
1779
|
-
|
|
2721
|
+
const own2 = (key) => utils$1.hasOwnProp(newConfig, key) ? newConfig[key] : void 0;
|
|
2722
|
+
const data = own2("data");
|
|
2723
|
+
let withXSRFToken = own2("withXSRFToken");
|
|
2724
|
+
const xsrfHeaderName = own2("xsrfHeaderName");
|
|
2725
|
+
const xsrfCookieName = own2("xsrfCookieName");
|
|
2726
|
+
let headers = own2("headers");
|
|
2727
|
+
const auth = own2("auth");
|
|
2728
|
+
const baseURL = own2("baseURL");
|
|
2729
|
+
const allowAbsoluteUrls = own2("allowAbsoluteUrls");
|
|
2730
|
+
const url = own2("url");
|
|
1780
2731
|
newConfig.headers = headers = AxiosHeaders$1.from(headers);
|
|
1781
|
-
newConfig.url = buildURL(
|
|
2732
|
+
newConfig.url = buildURL(
|
|
2733
|
+
buildFullPath(baseURL, url, allowAbsoluteUrls, newConfig),
|
|
2734
|
+
own2("params"),
|
|
2735
|
+
own2("paramsSerializer")
|
|
2736
|
+
);
|
|
1782
2737
|
if (auth) {
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
2738
|
+
const username = utils$1.getSafeProp(auth, "username") || "";
|
|
2739
|
+
const password = utils$1.getSafeProp(auth, "password") || "";
|
|
2740
|
+
try {
|
|
2741
|
+
headers.set(
|
|
2742
|
+
"Authorization",
|
|
2743
|
+
"Basic " + btoa(username + ":" + (password ? encodeUTF8$1(password) : ""))
|
|
2744
|
+
);
|
|
2745
|
+
} catch (e) {
|
|
2746
|
+
throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_OPTION_VALUE, config2);
|
|
2747
|
+
}
|
|
1787
2748
|
}
|
|
1788
2749
|
if (utils$1.isFormData(data)) {
|
|
1789
|
-
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
|
2750
|
+
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv || utils$1.isReactNative(data)) {
|
|
1790
2751
|
headers.setContentType(void 0);
|
|
1791
2752
|
} 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
|
-
});
|
|
2753
|
+
setFormDataHeaders(headers, data.getHeaders(), own2("formDataHeaderPolicy"));
|
|
1799
2754
|
}
|
|
1800
2755
|
}
|
|
1801
2756
|
if (platform.hasStandardBrowserEnv) {
|
|
1802
|
-
|
|
1803
|
-
|
|
2757
|
+
if (utils$1.isFunction(withXSRFToken)) {
|
|
2758
|
+
withXSRFToken = withXSRFToken(newConfig);
|
|
2759
|
+
}
|
|
2760
|
+
const shouldSendXSRF = withXSRFToken === true || withXSRFToken == null && isURLSameOrigin(newConfig.url);
|
|
2761
|
+
if (shouldSendXSRF) {
|
|
1804
2762
|
const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
|
|
1805
2763
|
if (xsrfValue) {
|
|
1806
2764
|
headers.set(xsrfHeaderName, xsrfValue);
|
|
@@ -1808,7 +2766,7 @@ const resolveConfig = (config2) => {
|
|
|
1808
2766
|
}
|
|
1809
2767
|
}
|
|
1810
2768
|
return newConfig;
|
|
1811
|
-
}
|
|
2769
|
+
}
|
|
1812
2770
|
const isXHRAdapterSupported = typeof XMLHttpRequest !== "undefined";
|
|
1813
2771
|
const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
1814
2772
|
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
@@ -1844,13 +2802,17 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1844
2802
|
config: config2,
|
|
1845
2803
|
request
|
|
1846
2804
|
};
|
|
1847
|
-
settle(
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
2805
|
+
settle(
|
|
2806
|
+
function _resolve(value) {
|
|
2807
|
+
resolve(value);
|
|
2808
|
+
done();
|
|
2809
|
+
},
|
|
2810
|
+
function _reject(err) {
|
|
2811
|
+
reject(err);
|
|
2812
|
+
done();
|
|
2813
|
+
},
|
|
2814
|
+
response
|
|
2815
|
+
);
|
|
1854
2816
|
request = null;
|
|
1855
2817
|
}
|
|
1856
2818
|
if ("onloadend" in request) {
|
|
@@ -1860,7 +2822,7 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1860
2822
|
if (!request || request.readyState !== 4) {
|
|
1861
2823
|
return;
|
|
1862
2824
|
}
|
|
1863
|
-
if (request.status === 0 && !(request.responseURL && request.responseURL.
|
|
2825
|
+
if (request.status === 0 && !(request.responseURL && request.responseURL.startsWith("file:"))) {
|
|
1864
2826
|
return;
|
|
1865
2827
|
}
|
|
1866
2828
|
setTimeout(onloadend);
|
|
@@ -1871,6 +2833,7 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1871
2833
|
return;
|
|
1872
2834
|
}
|
|
1873
2835
|
reject(new AxiosError$1("Request aborted", AxiosError$1.ECONNABORTED, config2, request));
|
|
2836
|
+
done();
|
|
1874
2837
|
request = null;
|
|
1875
2838
|
};
|
|
1876
2839
|
request.onerror = function handleError(event) {
|
|
@@ -1878,6 +2841,7 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1878
2841
|
const err = new AxiosError$1(msg, AxiosError$1.ERR_NETWORK, config2, request);
|
|
1879
2842
|
err.event = event || null;
|
|
1880
2843
|
reject(err);
|
|
2844
|
+
done();
|
|
1881
2845
|
request = null;
|
|
1882
2846
|
};
|
|
1883
2847
|
request.ontimeout = function handleTimeout() {
|
|
@@ -1886,17 +2850,20 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1886
2850
|
if (_config.timeoutErrorMessage) {
|
|
1887
2851
|
timeoutErrorMessage = _config.timeoutErrorMessage;
|
|
1888
2852
|
}
|
|
1889
|
-
reject(
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
2853
|
+
reject(
|
|
2854
|
+
new AxiosError$1(
|
|
2855
|
+
timeoutErrorMessage,
|
|
2856
|
+
transitional2.clarifyTimeoutError ? AxiosError$1.ETIMEDOUT : AxiosError$1.ECONNABORTED,
|
|
2857
|
+
config2,
|
|
2858
|
+
request
|
|
2859
|
+
)
|
|
2860
|
+
);
|
|
2861
|
+
done();
|
|
1895
2862
|
request = null;
|
|
1896
2863
|
};
|
|
1897
2864
|
requestData === void 0 && requestHeaders.setContentType(null);
|
|
1898
2865
|
if ("setRequestHeader" in request) {
|
|
1899
|
-
utils$1.forEach(requestHeaders
|
|
2866
|
+
utils$1.forEach(toByteStringHeaderObject(requestHeaders), function setRequestHeader(val, key) {
|
|
1900
2867
|
request.setRequestHeader(key, val);
|
|
1901
2868
|
});
|
|
1902
2869
|
}
|
|
@@ -1922,6 +2889,7 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1922
2889
|
}
|
|
1923
2890
|
reject(!cancel || cancel.type ? new CanceledError$1(null, config2, request) : cancel);
|
|
1924
2891
|
request.abort();
|
|
2892
|
+
done();
|
|
1925
2893
|
request = null;
|
|
1926
2894
|
};
|
|
1927
2895
|
_config.cancelToken && _config.cancelToken.subscribe(onCanceled);
|
|
@@ -1930,45 +2898,56 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1930
2898
|
}
|
|
1931
2899
|
}
|
|
1932
2900
|
const protocol = parseProtocol(_config.url);
|
|
1933
|
-
if (protocol && platform.protocols.
|
|
1934
|
-
reject(
|
|
2901
|
+
if (protocol && !platform.protocols.includes(protocol)) {
|
|
2902
|
+
reject(
|
|
2903
|
+
new AxiosError$1(
|
|
2904
|
+
"Unsupported protocol " + protocol + ":",
|
|
2905
|
+
AxiosError$1.ERR_BAD_REQUEST,
|
|
2906
|
+
config2
|
|
2907
|
+
)
|
|
2908
|
+
);
|
|
2909
|
+
done();
|
|
1935
2910
|
return;
|
|
1936
2911
|
}
|
|
1937
2912
|
request.send(requestData || null);
|
|
1938
2913
|
});
|
|
1939
2914
|
};
|
|
1940
2915
|
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;
|
|
2916
|
+
signals = signals ? signals.filter(Boolean) : [];
|
|
2917
|
+
if (!timeout && !signals.length) {
|
|
2918
|
+
return;
|
|
1971
2919
|
}
|
|
2920
|
+
const controller2 = new AbortController();
|
|
2921
|
+
let aborted = false;
|
|
2922
|
+
const onabort = function(reason) {
|
|
2923
|
+
if (!aborted) {
|
|
2924
|
+
aborted = true;
|
|
2925
|
+
unsubscribe();
|
|
2926
|
+
const err = reason instanceof Error ? reason : this.reason;
|
|
2927
|
+
controller2.abort(
|
|
2928
|
+
err instanceof AxiosError$1 ? err : new CanceledError$1(err instanceof Error ? err.message : err)
|
|
2929
|
+
);
|
|
2930
|
+
}
|
|
2931
|
+
};
|
|
2932
|
+
let timer = timeout && setTimeout(() => {
|
|
2933
|
+
timer = null;
|
|
2934
|
+
onabort(new AxiosError$1(`timeout of ${timeout}ms exceeded`, AxiosError$1.ETIMEDOUT));
|
|
2935
|
+
}, timeout);
|
|
2936
|
+
const unsubscribe = () => {
|
|
2937
|
+
if (!signals) {
|
|
2938
|
+
return;
|
|
2939
|
+
}
|
|
2940
|
+
timer && clearTimeout(timer);
|
|
2941
|
+
timer = null;
|
|
2942
|
+
signals.forEach((signal2) => {
|
|
2943
|
+
signal2.unsubscribe ? signal2.unsubscribe(onabort) : signal2.removeEventListener("abort", onabort);
|
|
2944
|
+
});
|
|
2945
|
+
signals = null;
|
|
2946
|
+
};
|
|
2947
|
+
signals.forEach((signal2) => signal2.addEventListener("abort", onabort, { once: true }));
|
|
2948
|
+
const { signal } = controller2;
|
|
2949
|
+
signal.unsubscribe = () => utils$1.asap(unsubscribe);
|
|
2950
|
+
return signal;
|
|
1972
2951
|
};
|
|
1973
2952
|
const streamChunk = function* (chunk, chunkSize) {
|
|
1974
2953
|
let len = chunk.byteLength;
|
|
@@ -2017,44 +2996,127 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
|
|
2017
2996
|
onFinish && onFinish(e);
|
|
2018
2997
|
}
|
|
2019
2998
|
};
|
|
2020
|
-
return new ReadableStream(
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2999
|
+
return new ReadableStream(
|
|
3000
|
+
{
|
|
3001
|
+
async pull(controller2) {
|
|
3002
|
+
try {
|
|
3003
|
+
const { done: done2, value } = await iterator2.next();
|
|
3004
|
+
if (done2) {
|
|
3005
|
+
_onFinish();
|
|
3006
|
+
controller2.close();
|
|
3007
|
+
return;
|
|
3008
|
+
}
|
|
3009
|
+
let len = value.byteLength;
|
|
3010
|
+
if (onProgress) {
|
|
3011
|
+
let loadedBytes = bytes += len;
|
|
3012
|
+
onProgress(loadedBytes);
|
|
3013
|
+
}
|
|
3014
|
+
controller2.enqueue(new Uint8Array(value));
|
|
3015
|
+
} catch (err) {
|
|
3016
|
+
_onFinish(err);
|
|
3017
|
+
throw err;
|
|
2033
3018
|
}
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
_onFinish(
|
|
2037
|
-
|
|
3019
|
+
},
|
|
3020
|
+
cancel(reason) {
|
|
3021
|
+
_onFinish(reason);
|
|
3022
|
+
return iterator2.return();
|
|
2038
3023
|
}
|
|
2039
3024
|
},
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
return iterator2.return();
|
|
3025
|
+
{
|
|
3026
|
+
highWaterMark: 2
|
|
2043
3027
|
}
|
|
2044
|
-
|
|
2045
|
-
highWaterMark: 2
|
|
2046
|
-
});
|
|
3028
|
+
);
|
|
2047
3029
|
};
|
|
3030
|
+
const isHexDigit = (charCode) => charCode >= 48 && charCode <= 57 || charCode >= 65 && charCode <= 70 || charCode >= 97 && charCode <= 102;
|
|
3031
|
+
const isPercentEncodedByte = (str2, i, len) => i + 2 < len && isHexDigit(str2.charCodeAt(i + 1)) && isHexDigit(str2.charCodeAt(i + 2));
|
|
3032
|
+
function estimateDataURLDecodedBytes(url) {
|
|
3033
|
+
if (!url || typeof url !== "string") return 0;
|
|
3034
|
+
if (!url.startsWith("data:")) return 0;
|
|
3035
|
+
const comma = url.indexOf(",");
|
|
3036
|
+
if (comma < 0) return 0;
|
|
3037
|
+
const meta = url.slice(5, comma);
|
|
3038
|
+
const body = url.slice(comma + 1);
|
|
3039
|
+
const isBase64 = /;base64/i.test(meta);
|
|
3040
|
+
if (isBase64) {
|
|
3041
|
+
let effectiveLen = body.length;
|
|
3042
|
+
const len = body.length;
|
|
3043
|
+
for (let i = 0; i < len; i++) {
|
|
3044
|
+
if (body.charCodeAt(i) === 37 && i + 2 < len) {
|
|
3045
|
+
const a = body.charCodeAt(i + 1);
|
|
3046
|
+
const b = body.charCodeAt(i + 2);
|
|
3047
|
+
const isHex = isHexDigit(a) && isHexDigit(b);
|
|
3048
|
+
if (isHex) {
|
|
3049
|
+
effectiveLen -= 2;
|
|
3050
|
+
i += 2;
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
let pad = 0;
|
|
3055
|
+
let idx = len - 1;
|
|
3056
|
+
const tailIsPct3D = (j) => j >= 2 && body.charCodeAt(j - 2) === 37 && // '%'
|
|
3057
|
+
body.charCodeAt(j - 1) === 51 && // '3'
|
|
3058
|
+
(body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100);
|
|
3059
|
+
if (idx >= 0) {
|
|
3060
|
+
if (body.charCodeAt(idx) === 61) {
|
|
3061
|
+
pad++;
|
|
3062
|
+
idx--;
|
|
3063
|
+
} else if (tailIsPct3D(idx)) {
|
|
3064
|
+
pad++;
|
|
3065
|
+
idx -= 3;
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
if (pad === 1 && idx >= 0) {
|
|
3069
|
+
if (body.charCodeAt(idx) === 61) {
|
|
3070
|
+
pad++;
|
|
3071
|
+
} else if (tailIsPct3D(idx)) {
|
|
3072
|
+
pad++;
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
const groups = Math.floor(effectiveLen / 4);
|
|
3076
|
+
const bytes2 = groups * 3 - (pad || 0);
|
|
3077
|
+
return bytes2 > 0 ? bytes2 : 0;
|
|
3078
|
+
}
|
|
3079
|
+
let bytes = 0;
|
|
3080
|
+
for (let i = 0, len = body.length; i < len; i++) {
|
|
3081
|
+
const c = body.charCodeAt(i);
|
|
3082
|
+
if (c === 37 && isPercentEncodedByte(body, i, len)) {
|
|
3083
|
+
bytes += 1;
|
|
3084
|
+
i += 2;
|
|
3085
|
+
} else if (c < 128) {
|
|
3086
|
+
bytes += 1;
|
|
3087
|
+
} else if (c < 2048) {
|
|
3088
|
+
bytes += 2;
|
|
3089
|
+
} else if (c >= 55296 && c <= 56319 && i + 1 < len) {
|
|
3090
|
+
const next = body.charCodeAt(i + 1);
|
|
3091
|
+
if (next >= 56320 && next <= 57343) {
|
|
3092
|
+
bytes += 4;
|
|
3093
|
+
i++;
|
|
3094
|
+
} else {
|
|
3095
|
+
bytes += 3;
|
|
3096
|
+
}
|
|
3097
|
+
} else {
|
|
3098
|
+
bytes += 3;
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
return bytes;
|
|
3102
|
+
}
|
|
3103
|
+
const VERSION$1 = "1.18.1";
|
|
2048
3104
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
2049
3105
|
const { isFunction } = utils$1;
|
|
2050
|
-
const
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
const {
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
}
|
|
3106
|
+
const encodeUTF8 = (str2) => encodeURIComponent(str2).replace(
|
|
3107
|
+
/%([0-9A-F]{2})/gi,
|
|
3108
|
+
(_, hex) => String.fromCharCode(parseInt(hex, 16))
|
|
3109
|
+
);
|
|
3110
|
+
const decodeURIComponentSafe = (value) => {
|
|
3111
|
+
if (!utils$1.isString(value)) {
|
|
3112
|
+
return value;
|
|
3113
|
+
}
|
|
3114
|
+
try {
|
|
3115
|
+
return decodeURIComponent(value);
|
|
3116
|
+
} catch (error) {
|
|
3117
|
+
return value;
|
|
3118
|
+
}
|
|
3119
|
+
};
|
|
2058
3120
|
const test = (fn, ...args) => {
|
|
2059
3121
|
try {
|
|
2060
3122
|
return !!fn(...args);
|
|
@@ -2062,10 +3124,27 @@ const test = (fn, ...args) => {
|
|
|
2062
3124
|
return false;
|
|
2063
3125
|
}
|
|
2064
3126
|
};
|
|
3127
|
+
const maybeWithAuthCredentials = (url) => {
|
|
3128
|
+
const protocolIndex = url.indexOf("://");
|
|
3129
|
+
let urlToCheck = url;
|
|
3130
|
+
if (protocolIndex !== -1) {
|
|
3131
|
+
urlToCheck = urlToCheck.slice(protocolIndex + 3);
|
|
3132
|
+
}
|
|
3133
|
+
return urlToCheck.includes("@") || urlToCheck.includes(":");
|
|
3134
|
+
};
|
|
2065
3135
|
const factory = (env) => {
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
3136
|
+
const globalObject = utils$1.global !== void 0 && utils$1.global !== null ? utils$1.global : globalThis;
|
|
3137
|
+
const { ReadableStream: ReadableStream2, TextEncoder } = globalObject;
|
|
3138
|
+
env = utils$1.merge.call(
|
|
3139
|
+
{
|
|
3140
|
+
skipUndefined: true
|
|
3141
|
+
},
|
|
3142
|
+
{
|
|
3143
|
+
Request: globalObject.Request,
|
|
3144
|
+
Response: globalObject.Response
|
|
3145
|
+
},
|
|
3146
|
+
env
|
|
3147
|
+
);
|
|
2069
3148
|
const { fetch: envFetch, Request, Response } = env;
|
|
2070
3149
|
const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === "function";
|
|
2071
3150
|
const isRequestSupported = isFunction(Request);
|
|
@@ -2073,18 +3152,22 @@ const factory = (env) => {
|
|
|
2073
3152
|
if (!isFetchSupported) {
|
|
2074
3153
|
return false;
|
|
2075
3154
|
}
|
|
2076
|
-
const isReadableStreamSupported = isFetchSupported && isFunction(
|
|
2077
|
-
const encodeText = isFetchSupported && (typeof TextEncoder === "function" ? /* @__PURE__ */ ((encoder) => (
|
|
3155
|
+
const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream2);
|
|
3156
|
+
const encodeText = isFetchSupported && (typeof TextEncoder === "function" ? /* @__PURE__ */ ((encoder) => (str2) => encoder.encode(str2))(new TextEncoder()) : async (str2) => new Uint8Array(await new Request(str2).arrayBuffer()));
|
|
2078
3157
|
const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
|
2079
3158
|
let duplexAccessed = false;
|
|
2080
|
-
const
|
|
2081
|
-
body: new
|
|
3159
|
+
const request = new Request(platform.origin, {
|
|
3160
|
+
body: new ReadableStream2(),
|
|
2082
3161
|
method: "POST",
|
|
2083
3162
|
get duplex() {
|
|
2084
3163
|
duplexAccessed = true;
|
|
2085
3164
|
return "half";
|
|
2086
3165
|
}
|
|
2087
|
-
})
|
|
3166
|
+
});
|
|
3167
|
+
const hasContentType = request.headers.has("Content-Type");
|
|
3168
|
+
if (request.body != null) {
|
|
3169
|
+
request.body.cancel();
|
|
3170
|
+
}
|
|
2088
3171
|
return duplexAccessed && !hasContentType;
|
|
2089
3172
|
});
|
|
2090
3173
|
const supportsResponseStream = isResponseSupported && isReadableStreamSupported && test(() => utils$1.isReadableStream(new Response("").body));
|
|
@@ -2098,7 +3181,11 @@ const factory = (env) => {
|
|
|
2098
3181
|
if (method) {
|
|
2099
3182
|
return method.call(res);
|
|
2100
3183
|
}
|
|
2101
|
-
throw new AxiosError$1(
|
|
3184
|
+
throw new AxiosError$1(
|
|
3185
|
+
`Response type '${type}' is not supported`,
|
|
3186
|
+
AxiosError$1.ERR_NOT_SUPPORT,
|
|
3187
|
+
config2
|
|
3188
|
+
);
|
|
2102
3189
|
});
|
|
2103
3190
|
});
|
|
2104
3191
|
})();
|
|
@@ -2143,63 +3230,189 @@ const factory = (env) => {
|
|
|
2143
3230
|
responseType,
|
|
2144
3231
|
headers,
|
|
2145
3232
|
withCredentials = "same-origin",
|
|
2146
|
-
fetchOptions
|
|
3233
|
+
fetchOptions,
|
|
3234
|
+
maxContentLength,
|
|
3235
|
+
maxBodyLength
|
|
2147
3236
|
} = resolveConfig(config2);
|
|
3237
|
+
const hasMaxContentLength = utils$1.isNumber(maxContentLength) && maxContentLength > -1;
|
|
3238
|
+
const hasMaxBodyLength = utils$1.isNumber(maxBodyLength) && maxBodyLength > -1;
|
|
3239
|
+
const own2 = (key) => utils$1.hasOwnProp(config2, key) ? config2[key] : void 0;
|
|
2148
3240
|
let _fetch = envFetch || fetch;
|
|
2149
3241
|
responseType = responseType ? (responseType + "").toLowerCase() : "text";
|
|
2150
|
-
let composedSignal = composeSignals(
|
|
3242
|
+
let composedSignal = composeSignals(
|
|
3243
|
+
[signal, cancelToken && cancelToken.toAbortSignal()],
|
|
3244
|
+
timeout
|
|
3245
|
+
);
|
|
2151
3246
|
let request = null;
|
|
2152
3247
|
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
2153
3248
|
composedSignal.unsubscribe();
|
|
2154
3249
|
});
|
|
2155
3250
|
let requestContentLength;
|
|
3251
|
+
let pendingBodyError = null;
|
|
3252
|
+
const maxBodyLengthError = () => new AxiosError$1(
|
|
3253
|
+
"Request body larger than maxBodyLength limit",
|
|
3254
|
+
AxiosError$1.ERR_BAD_REQUEST,
|
|
3255
|
+
config2,
|
|
3256
|
+
request
|
|
3257
|
+
);
|
|
2156
3258
|
try {
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
3259
|
+
let auth = void 0;
|
|
3260
|
+
const configAuth = own2("auth");
|
|
3261
|
+
if (configAuth) {
|
|
3262
|
+
const username = utils$1.getSafeProp(configAuth, "username") || "";
|
|
3263
|
+
const password = utils$1.getSafeProp(configAuth, "password") || "";
|
|
3264
|
+
auth = {
|
|
3265
|
+
username,
|
|
3266
|
+
password
|
|
3267
|
+
};
|
|
3268
|
+
}
|
|
3269
|
+
if (maybeWithAuthCredentials(url)) {
|
|
3270
|
+
const parsedURL = new URL(url, platform.origin);
|
|
3271
|
+
if (!auth && (parsedURL.username || parsedURL.password)) {
|
|
3272
|
+
const urlUsername = decodeURIComponentSafe(parsedURL.username);
|
|
3273
|
+
const urlPassword = decodeURIComponentSafe(parsedURL.password);
|
|
3274
|
+
auth = {
|
|
3275
|
+
username: urlUsername,
|
|
3276
|
+
password: urlPassword
|
|
3277
|
+
};
|
|
3278
|
+
}
|
|
3279
|
+
if (parsedURL.username || parsedURL.password) {
|
|
3280
|
+
parsedURL.username = "";
|
|
3281
|
+
parsedURL.password = "";
|
|
3282
|
+
url = parsedURL.href;
|
|
2166
3283
|
}
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
3284
|
+
}
|
|
3285
|
+
if (auth) {
|
|
3286
|
+
headers.delete("authorization");
|
|
3287
|
+
headers.set(
|
|
3288
|
+
"Authorization",
|
|
3289
|
+
"Basic " + btoa(encodeUTF8((auth.username || "") + ":" + (auth.password || "")))
|
|
3290
|
+
);
|
|
3291
|
+
}
|
|
3292
|
+
if (hasMaxContentLength && typeof url === "string" && url.startsWith("data:")) {
|
|
3293
|
+
const estimated = estimateDataURLDecodedBytes(url);
|
|
3294
|
+
if (estimated > maxContentLength) {
|
|
3295
|
+
throw new AxiosError$1(
|
|
3296
|
+
"maxContentLength size of " + maxContentLength + " exceeded",
|
|
3297
|
+
AxiosError$1.ERR_BAD_RESPONSE,
|
|
3298
|
+
config2,
|
|
3299
|
+
request
|
|
2171
3300
|
);
|
|
2172
|
-
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
|
2173
3301
|
}
|
|
2174
3302
|
}
|
|
3303
|
+
if (hasMaxBodyLength && method !== "get" && method !== "head") {
|
|
3304
|
+
const outboundLength = await getBodyLength(data);
|
|
3305
|
+
if (typeof outboundLength === "number" && isFinite(outboundLength)) {
|
|
3306
|
+
requestContentLength = outboundLength;
|
|
3307
|
+
if (outboundLength > maxBodyLength) {
|
|
3308
|
+
throw maxBodyLengthError();
|
|
3309
|
+
}
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
const mustEnforceStreamBody = hasMaxBodyLength && (utils$1.isReadableStream(data) || utils$1.isStream(data));
|
|
3313
|
+
const trackRequestStream = (stream, onProgress, flush) => trackStream(
|
|
3314
|
+
stream,
|
|
3315
|
+
DEFAULT_CHUNK_SIZE,
|
|
3316
|
+
(loadedBytes) => {
|
|
3317
|
+
if (hasMaxBodyLength && loadedBytes > maxBodyLength) {
|
|
3318
|
+
throw pendingBodyError = maxBodyLengthError();
|
|
3319
|
+
}
|
|
3320
|
+
onProgress && onProgress(loadedBytes);
|
|
3321
|
+
},
|
|
3322
|
+
flush
|
|
3323
|
+
);
|
|
3324
|
+
if (supportsRequestStream && method !== "get" && method !== "head" && (onUploadProgress || mustEnforceStreamBody)) {
|
|
3325
|
+
requestContentLength = requestContentLength == null ? await resolveBodyLength(headers, data) : requestContentLength;
|
|
3326
|
+
if (requestContentLength !== 0 || mustEnforceStreamBody) {
|
|
3327
|
+
let _request = new Request(url, {
|
|
3328
|
+
method: "POST",
|
|
3329
|
+
body: data,
|
|
3330
|
+
duplex: "half"
|
|
3331
|
+
});
|
|
3332
|
+
let contentTypeHeader;
|
|
3333
|
+
if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get("content-type"))) {
|
|
3334
|
+
headers.setContentType(contentTypeHeader);
|
|
3335
|
+
}
|
|
3336
|
+
if (_request.body) {
|
|
3337
|
+
const [onProgress, flush] = onUploadProgress && progressEventDecorator(
|
|
3338
|
+
requestContentLength,
|
|
3339
|
+
progressEventReducer(asyncDecorator(onUploadProgress))
|
|
3340
|
+
) || [];
|
|
3341
|
+
data = trackRequestStream(_request.body, onProgress, flush);
|
|
3342
|
+
}
|
|
3343
|
+
}
|
|
3344
|
+
} else if (mustEnforceStreamBody && !isRequestSupported && isReadableStreamSupported && method !== "get" && method !== "head") {
|
|
3345
|
+
data = trackRequestStream(data);
|
|
3346
|
+
} else if (mustEnforceStreamBody && isRequestSupported && !supportsRequestStream && method !== "get" && method !== "head") {
|
|
3347
|
+
throw new AxiosError$1(
|
|
3348
|
+
"Stream request bodies are not supported by the current fetch implementation",
|
|
3349
|
+
AxiosError$1.ERR_NOT_SUPPORT,
|
|
3350
|
+
config2,
|
|
3351
|
+
request
|
|
3352
|
+
);
|
|
3353
|
+
}
|
|
2175
3354
|
if (!utils$1.isString(withCredentials)) {
|
|
2176
3355
|
withCredentials = withCredentials ? "include" : "omit";
|
|
2177
3356
|
}
|
|
2178
3357
|
const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
|
|
3358
|
+
if (utils$1.isFormData(data)) {
|
|
3359
|
+
const contentType = headers.getContentType();
|
|
3360
|
+
if (contentType && /^multipart\/form-data/i.test(contentType) && !/boundary=/i.test(contentType)) {
|
|
3361
|
+
headers.delete("content-type");
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
headers.set("User-Agent", "axios/" + VERSION$1, false);
|
|
2179
3365
|
const resolvedOptions = {
|
|
2180
3366
|
...fetchOptions,
|
|
2181
3367
|
signal: composedSignal,
|
|
2182
3368
|
method: method.toUpperCase(),
|
|
2183
|
-
headers: headers.normalize()
|
|
3369
|
+
headers: toByteStringHeaderObject(headers.normalize()),
|
|
2184
3370
|
body: data,
|
|
2185
3371
|
duplex: "half",
|
|
2186
3372
|
credentials: isCredentialsSupported ? withCredentials : void 0
|
|
2187
3373
|
};
|
|
2188
3374
|
request = isRequestSupported && new Request(url, resolvedOptions);
|
|
2189
3375
|
let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
|
|
3376
|
+
const responseHeaders = AxiosHeaders$1.from(response.headers);
|
|
3377
|
+
if (hasMaxContentLength) {
|
|
3378
|
+
const declaredLength = utils$1.toFiniteNumber(responseHeaders.getContentLength());
|
|
3379
|
+
if (declaredLength != null && declaredLength > maxContentLength) {
|
|
3380
|
+
throw new AxiosError$1(
|
|
3381
|
+
"maxContentLength size of " + maxContentLength + " exceeded",
|
|
3382
|
+
AxiosError$1.ERR_BAD_RESPONSE,
|
|
3383
|
+
config2,
|
|
3384
|
+
request
|
|
3385
|
+
);
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
2190
3388
|
const isStreamResponse = supportsResponseStream && (responseType === "stream" || responseType === "response");
|
|
2191
|
-
if (supportsResponseStream && (onDownloadProgress || isStreamResponse && unsubscribe)) {
|
|
3389
|
+
if (supportsResponseStream && response.body && (onDownloadProgress || hasMaxContentLength || isStreamResponse && unsubscribe)) {
|
|
2192
3390
|
const options = {};
|
|
2193
3391
|
["status", "statusText", "headers"].forEach((prop) => {
|
|
2194
3392
|
options[prop] = response[prop];
|
|
2195
3393
|
});
|
|
2196
|
-
const responseContentLength = utils$1.toFiniteNumber(
|
|
3394
|
+
const responseContentLength = utils$1.toFiniteNumber(responseHeaders.getContentLength());
|
|
2197
3395
|
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
|
2198
3396
|
responseContentLength,
|
|
2199
3397
|
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
|
2200
3398
|
) || [];
|
|
3399
|
+
let bytesRead = 0;
|
|
3400
|
+
const onChunkProgress = (loadedBytes) => {
|
|
3401
|
+
if (hasMaxContentLength) {
|
|
3402
|
+
bytesRead = loadedBytes;
|
|
3403
|
+
if (bytesRead > maxContentLength) {
|
|
3404
|
+
throw new AxiosError$1(
|
|
3405
|
+
"maxContentLength size of " + maxContentLength + " exceeded",
|
|
3406
|
+
AxiosError$1.ERR_BAD_RESPONSE,
|
|
3407
|
+
config2,
|
|
3408
|
+
request
|
|
3409
|
+
);
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
onProgress && onProgress(loadedBytes);
|
|
3413
|
+
};
|
|
2201
3414
|
response = new Response(
|
|
2202
|
-
trackStream(response.body, DEFAULT_CHUNK_SIZE,
|
|
3415
|
+
trackStream(response.body, DEFAULT_CHUNK_SIZE, onChunkProgress, () => {
|
|
2203
3416
|
flush && flush();
|
|
2204
3417
|
unsubscribe && unsubscribe();
|
|
2205
3418
|
}),
|
|
@@ -2207,7 +3420,30 @@ const factory = (env) => {
|
|
|
2207
3420
|
);
|
|
2208
3421
|
}
|
|
2209
3422
|
responseType = responseType || "text";
|
|
2210
|
-
let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || "text"](
|
|
3423
|
+
let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || "text"](
|
|
3424
|
+
response,
|
|
3425
|
+
config2
|
|
3426
|
+
);
|
|
3427
|
+
if (hasMaxContentLength && !supportsResponseStream && !isStreamResponse) {
|
|
3428
|
+
let materializedSize;
|
|
3429
|
+
if (responseData != null) {
|
|
3430
|
+
if (typeof responseData.byteLength === "number") {
|
|
3431
|
+
materializedSize = responseData.byteLength;
|
|
3432
|
+
} else if (typeof responseData.size === "number") {
|
|
3433
|
+
materializedSize = responseData.size;
|
|
3434
|
+
} else if (typeof responseData === "string") {
|
|
3435
|
+
materializedSize = typeof TextEncoder === "function" ? new TextEncoder().encode(responseData).byteLength : responseData.length;
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3438
|
+
if (typeof materializedSize === "number" && materializedSize > maxContentLength) {
|
|
3439
|
+
throw new AxiosError$1(
|
|
3440
|
+
"maxContentLength size of " + maxContentLength + " exceeded",
|
|
3441
|
+
AxiosError$1.ERR_BAD_RESPONSE,
|
|
3442
|
+
config2,
|
|
3443
|
+
request
|
|
3444
|
+
);
|
|
3445
|
+
}
|
|
3446
|
+
}
|
|
2211
3447
|
!isStreamResponse && unsubscribe && unsubscribe();
|
|
2212
3448
|
return await new Promise((resolve, reject) => {
|
|
2213
3449
|
settle(resolve, reject, {
|
|
@@ -2221,27 +3457,55 @@ const factory = (env) => {
|
|
|
2221
3457
|
});
|
|
2222
3458
|
} catch (err) {
|
|
2223
3459
|
unsubscribe && unsubscribe();
|
|
3460
|
+
if (composedSignal && composedSignal.aborted && composedSignal.reason instanceof AxiosError$1) {
|
|
3461
|
+
const canceledError = composedSignal.reason;
|
|
3462
|
+
canceledError.config = config2;
|
|
3463
|
+
request && (canceledError.request = request);
|
|
3464
|
+
if (err !== canceledError) {
|
|
3465
|
+
Object.defineProperty(canceledError, "cause", {
|
|
3466
|
+
__proto__: null,
|
|
3467
|
+
value: err,
|
|
3468
|
+
writable: true,
|
|
3469
|
+
enumerable: false,
|
|
3470
|
+
configurable: true
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3473
|
+
throw canceledError;
|
|
3474
|
+
}
|
|
3475
|
+
if (pendingBodyError) {
|
|
3476
|
+
request && !pendingBodyError.request && (pendingBodyError.request = request);
|
|
3477
|
+
throw pendingBodyError;
|
|
3478
|
+
}
|
|
3479
|
+
if (err instanceof AxiosError$1) {
|
|
3480
|
+
request && !err.request && (err.request = request);
|
|
3481
|
+
throw err;
|
|
3482
|
+
}
|
|
2224
3483
|
if (err && err.name === "TypeError" && /Load failed|fetch/i.test(err.message)) {
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
3484
|
+
const networkError = new AxiosError$1(
|
|
3485
|
+
"Network Error",
|
|
3486
|
+
AxiosError$1.ERR_NETWORK,
|
|
3487
|
+
config2,
|
|
3488
|
+
request,
|
|
3489
|
+
err && err.response
|
|
2230
3490
|
);
|
|
3491
|
+
Object.defineProperty(networkError, "cause", {
|
|
3492
|
+
__proto__: null,
|
|
3493
|
+
value: err.cause || err,
|
|
3494
|
+
writable: true,
|
|
3495
|
+
enumerable: false,
|
|
3496
|
+
configurable: true
|
|
3497
|
+
});
|
|
3498
|
+
throw networkError;
|
|
2231
3499
|
}
|
|
2232
|
-
throw AxiosError$1.from(err, err && err.code, config2, request);
|
|
3500
|
+
throw AxiosError$1.from(err, err && err.code, config2, request, err && err.response);
|
|
2233
3501
|
}
|
|
2234
3502
|
};
|
|
2235
3503
|
};
|
|
2236
3504
|
const seedCache = /* @__PURE__ */ new Map();
|
|
2237
3505
|
const getFetch = (config2) => {
|
|
2238
|
-
let env = config2
|
|
3506
|
+
let env = config2 && config2.env || {};
|
|
2239
3507
|
const { fetch: fetch2, Request, Response } = env;
|
|
2240
|
-
const seeds = [
|
|
2241
|
-
Request,
|
|
2242
|
-
Response,
|
|
2243
|
-
fetch2
|
|
2244
|
-
];
|
|
3508
|
+
const seeds = [Request, Response, fetch2];
|
|
2245
3509
|
let len = seeds.length, i = len, seed, target, map = seedCache;
|
|
2246
3510
|
while (i--) {
|
|
2247
3511
|
seed = seeds[i];
|
|
@@ -2262,48 +3526,57 @@ const knownAdapters = {
|
|
|
2262
3526
|
utils$1.forEach(knownAdapters, (fn, value) => {
|
|
2263
3527
|
if (fn) {
|
|
2264
3528
|
try {
|
|
2265
|
-
Object.defineProperty(fn, "name", { value });
|
|
3529
|
+
Object.defineProperty(fn, "name", { __proto__: null, value });
|
|
2266
3530
|
} catch (e) {
|
|
2267
3531
|
}
|
|
2268
|
-
Object.defineProperty(fn, "adapterName", { value });
|
|
3532
|
+
Object.defineProperty(fn, "adapterName", { __proto__: null, value });
|
|
2269
3533
|
}
|
|
2270
3534
|
});
|
|
2271
3535
|
const renderReason = (reason) => `- ${reason}`;
|
|
2272
3536
|
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;
|
|
3537
|
+
function getAdapter$1(adapters2, config2) {
|
|
3538
|
+
adapters2 = utils$1.isArray(adapters2) ? adapters2 : [adapters2];
|
|
3539
|
+
const { length } = adapters2;
|
|
3540
|
+
let nameOrAdapter;
|
|
3541
|
+
let adapter;
|
|
3542
|
+
const rejectedReasons = {};
|
|
3543
|
+
for (let i = 0; i < length; i++) {
|
|
3544
|
+
nameOrAdapter = adapters2[i];
|
|
3545
|
+
let id;
|
|
3546
|
+
adapter = nameOrAdapter;
|
|
3547
|
+
if (!isResolvedHandle(nameOrAdapter)) {
|
|
3548
|
+
adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
|
3549
|
+
if (adapter === void 0) {
|
|
3550
|
+
throw new AxiosError$1(`Unknown adapter '${id}'`);
|
|
2292
3551
|
}
|
|
2293
|
-
rejectedReasons[id || "#" + i] = adapter;
|
|
2294
3552
|
}
|
|
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
|
-
);
|
|
3553
|
+
if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config2)))) {
|
|
3554
|
+
break;
|
|
2304
3555
|
}
|
|
2305
|
-
|
|
2306
|
-
}
|
|
3556
|
+
rejectedReasons[id || "#" + i] = adapter;
|
|
3557
|
+
}
|
|
3558
|
+
if (!adapter) {
|
|
3559
|
+
const reasons = Object.entries(rejectedReasons).map(
|
|
3560
|
+
([id, state]) => `adapter ${id} ` + (state === false ? "is not supported by the environment" : "is not available in the build")
|
|
3561
|
+
);
|
|
3562
|
+
let s = length ? reasons.length > 1 ? "since :\n" + reasons.map(renderReason).join("\n") : " " + renderReason(reasons[0]) : "as no adapter specified";
|
|
3563
|
+
throw new AxiosError$1(
|
|
3564
|
+
`There is no suitable adapter to dispatch the request ` + s,
|
|
3565
|
+
AxiosError$1.ERR_NOT_SUPPORT
|
|
3566
|
+
);
|
|
3567
|
+
}
|
|
3568
|
+
return adapter;
|
|
3569
|
+
}
|
|
3570
|
+
const adapters = {
|
|
3571
|
+
/**
|
|
3572
|
+
* Resolve an adapter from a list of adapter names or functions.
|
|
3573
|
+
* @type {Function}
|
|
3574
|
+
*/
|
|
3575
|
+
getAdapter: getAdapter$1,
|
|
3576
|
+
/**
|
|
3577
|
+
* Exposes all known adapters
|
|
3578
|
+
* @type {Object<string, Function|Object>}
|
|
3579
|
+
*/
|
|
2307
3580
|
adapters: knownAdapters
|
|
2308
3581
|
};
|
|
2309
3582
|
function throwIfCancellationRequested(config2) {
|
|
@@ -2317,39 +3590,44 @@ function throwIfCancellationRequested(config2) {
|
|
|
2317
3590
|
function dispatchRequest(config2) {
|
|
2318
3591
|
throwIfCancellationRequested(config2);
|
|
2319
3592
|
config2.headers = AxiosHeaders$1.from(config2.headers);
|
|
2320
|
-
config2.data = transformData.call(
|
|
2321
|
-
config2,
|
|
2322
|
-
config2.transformRequest
|
|
2323
|
-
);
|
|
3593
|
+
config2.data = transformData.call(config2, config2.transformRequest);
|
|
2324
3594
|
if (["post", "put", "patch"].indexOf(config2.method) !== -1) {
|
|
2325
3595
|
config2.headers.setContentType("application/x-www-form-urlencoded", false);
|
|
2326
3596
|
}
|
|
2327
3597
|
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)) {
|
|
3598
|
+
return adapter(config2).then(
|
|
3599
|
+
function onAdapterResolution(response) {
|
|
2339
3600
|
throwIfCancellationRequested(config2);
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
3601
|
+
config2.response = response;
|
|
3602
|
+
try {
|
|
3603
|
+
response.data = transformData.call(config2, config2.transformResponse, response);
|
|
3604
|
+
} finally {
|
|
3605
|
+
delete config2.response;
|
|
3606
|
+
}
|
|
3607
|
+
response.headers = AxiosHeaders$1.from(response.headers);
|
|
3608
|
+
return response;
|
|
3609
|
+
},
|
|
3610
|
+
function onAdapterRejection(reason) {
|
|
3611
|
+
if (!isCancel$1(reason)) {
|
|
3612
|
+
throwIfCancellationRequested(config2);
|
|
3613
|
+
if (reason && reason.response) {
|
|
3614
|
+
config2.response = reason.response;
|
|
3615
|
+
try {
|
|
3616
|
+
reason.response.data = transformData.call(
|
|
3617
|
+
config2,
|
|
3618
|
+
config2.transformResponse,
|
|
3619
|
+
reason.response
|
|
3620
|
+
);
|
|
3621
|
+
} finally {
|
|
3622
|
+
delete config2.response;
|
|
3623
|
+
}
|
|
3624
|
+
reason.response.headers = AxiosHeaders$1.from(reason.response.headers);
|
|
3625
|
+
}
|
|
2347
3626
|
}
|
|
3627
|
+
return Promise.reject(reason);
|
|
2348
3628
|
}
|
|
2349
|
-
|
|
2350
|
-
});
|
|
3629
|
+
);
|
|
2351
3630
|
}
|
|
2352
|
-
const VERSION$1 = "1.12.2";
|
|
2353
3631
|
const validators$1 = {};
|
|
2354
3632
|
["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i) => {
|
|
2355
3633
|
validators$1[type] = function validator2(thing) {
|
|
@@ -2386,20 +3664,23 @@ validators$1.spelling = function spelling(correctSpelling) {
|
|
|
2386
3664
|
return true;
|
|
2387
3665
|
};
|
|
2388
3666
|
};
|
|
2389
|
-
function assertOptions(options,
|
|
2390
|
-
if (typeof options !== "object") {
|
|
3667
|
+
function assertOptions(options, schema2, allowUnknown) {
|
|
3668
|
+
if (typeof options !== "object" || options === null) {
|
|
2391
3669
|
throw new AxiosError$1("options must be an object", AxiosError$1.ERR_BAD_OPTION_VALUE);
|
|
2392
3670
|
}
|
|
2393
3671
|
const keys = Object.keys(options);
|
|
2394
3672
|
let i = keys.length;
|
|
2395
3673
|
while (i-- > 0) {
|
|
2396
3674
|
const opt = keys[i];
|
|
2397
|
-
const validator2 =
|
|
3675
|
+
const validator2 = Object.prototype.hasOwnProperty.call(schema2, opt) ? schema2[opt] : void 0;
|
|
2398
3676
|
if (validator2) {
|
|
2399
3677
|
const value = options[opt];
|
|
2400
3678
|
const result = value === void 0 || validator2(value, opt, options);
|
|
2401
3679
|
if (result !== true) {
|
|
2402
|
-
throw new AxiosError$1(
|
|
3680
|
+
throw new AxiosError$1(
|
|
3681
|
+
"option " + opt + " must be " + result,
|
|
3682
|
+
AxiosError$1.ERR_BAD_OPTION_VALUE
|
|
3683
|
+
);
|
|
2403
3684
|
}
|
|
2404
3685
|
continue;
|
|
2405
3686
|
}
|
|
@@ -2436,12 +3717,23 @@ let Axios$1 = class Axios {
|
|
|
2436
3717
|
if (err instanceof Error) {
|
|
2437
3718
|
let dummy = {};
|
|
2438
3719
|
Error.captureStackTrace ? Error.captureStackTrace(dummy) : dummy = new Error();
|
|
2439
|
-
const stack =
|
|
3720
|
+
const stack = (() => {
|
|
3721
|
+
if (!dummy.stack) {
|
|
3722
|
+
return "";
|
|
3723
|
+
}
|
|
3724
|
+
const firstNewlineIndex = dummy.stack.indexOf("\n");
|
|
3725
|
+
return firstNewlineIndex === -1 ? "" : dummy.stack.slice(firstNewlineIndex + 1);
|
|
3726
|
+
})();
|
|
2440
3727
|
try {
|
|
2441
3728
|
if (!err.stack) {
|
|
2442
3729
|
err.stack = stack;
|
|
2443
|
-
} else if (stack
|
|
2444
|
-
|
|
3730
|
+
} else if (stack) {
|
|
3731
|
+
const firstNewlineIndex = stack.indexOf("\n");
|
|
3732
|
+
const secondNewlineIndex = firstNewlineIndex === -1 ? -1 : stack.indexOf("\n", firstNewlineIndex + 1);
|
|
3733
|
+
const stackWithoutTwoTopLines = secondNewlineIndex === -1 ? "" : stack.slice(secondNewlineIndex + 1);
|
|
3734
|
+
if (!String(err.stack).endsWith(stackWithoutTwoTopLines)) {
|
|
3735
|
+
err.stack += "\n" + stack;
|
|
3736
|
+
}
|
|
2445
3737
|
}
|
|
2446
3738
|
} catch (e) {
|
|
2447
3739
|
}
|
|
@@ -2459,11 +3751,18 @@ let Axios$1 = class Axios {
|
|
|
2459
3751
|
config2 = mergeConfig$1(this.defaults, config2);
|
|
2460
3752
|
const { transitional: transitional2, paramsSerializer, headers } = config2;
|
|
2461
3753
|
if (transitional2 !== void 0) {
|
|
2462
|
-
validator.assertOptions(
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
3754
|
+
validator.assertOptions(
|
|
3755
|
+
transitional2,
|
|
3756
|
+
{
|
|
3757
|
+
silentJSONParsing: validators.transitional(validators.boolean),
|
|
3758
|
+
forcedJSONParsing: validators.transitional(validators.boolean),
|
|
3759
|
+
clarifyTimeoutError: validators.transitional(validators.boolean),
|
|
3760
|
+
legacyInterceptorReqResOrdering: validators.transitional(validators.boolean),
|
|
3761
|
+
advertiseZstdAcceptEncoding: validators.transitional(validators.boolean),
|
|
3762
|
+
validateStatusUndefinedResolves: validators.transitional(validators.boolean)
|
|
3763
|
+
},
|
|
3764
|
+
false
|
|
3765
|
+
);
|
|
2467
3766
|
}
|
|
2468
3767
|
if (paramsSerializer != null) {
|
|
2469
3768
|
if (utils$1.isFunction(paramsSerializer)) {
|
|
@@ -2471,10 +3770,14 @@ let Axios$1 = class Axios {
|
|
|
2471
3770
|
serialize: paramsSerializer
|
|
2472
3771
|
};
|
|
2473
3772
|
} else {
|
|
2474
|
-
validator.assertOptions(
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
3773
|
+
validator.assertOptions(
|
|
3774
|
+
paramsSerializer,
|
|
3775
|
+
{
|
|
3776
|
+
encode: validators.function,
|
|
3777
|
+
serialize: validators.function
|
|
3778
|
+
},
|
|
3779
|
+
true
|
|
3780
|
+
);
|
|
2478
3781
|
}
|
|
2479
3782
|
}
|
|
2480
3783
|
if (config2.allowAbsoluteUrls !== void 0) ;
|
|
@@ -2483,21 +3786,19 @@ let Axios$1 = class Axios {
|
|
|
2483
3786
|
} else {
|
|
2484
3787
|
config2.allowAbsoluteUrls = true;
|
|
2485
3788
|
}
|
|
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
|
-
}
|
|
3789
|
+
validator.assertOptions(
|
|
3790
|
+
config2,
|
|
3791
|
+
{
|
|
3792
|
+
baseUrl: validators.spelling("baseURL"),
|
|
3793
|
+
withXsrfToken: validators.spelling("withXSRFToken")
|
|
3794
|
+
},
|
|
3795
|
+
true
|
|
2500
3796
|
);
|
|
3797
|
+
config2.method = (config2.method || this.defaults.method || "get").toLowerCase();
|
|
3798
|
+
let contextHeaders = headers && utils$1.merge(headers.common, headers[config2.method]);
|
|
3799
|
+
headers && utils$1.forEach(["delete", "get", "head", "post", "put", "patch", "query", "common"], (method) => {
|
|
3800
|
+
delete headers[method];
|
|
3801
|
+
});
|
|
2501
3802
|
config2.headers = AxiosHeaders$1.concat(contextHeaders, headers);
|
|
2502
3803
|
const requestInterceptorChain = [];
|
|
2503
3804
|
let synchronousRequestInterceptors = true;
|
|
@@ -2506,7 +3807,13 @@ let Axios$1 = class Axios {
|
|
|
2506
3807
|
return;
|
|
2507
3808
|
}
|
|
2508
3809
|
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
|
2509
|
-
|
|
3810
|
+
const transitional3 = config2.transitional || transitionalDefaults;
|
|
3811
|
+
const legacyInterceptorReqResOrdering = transitional3 && transitional3.legacyInterceptorReqResOrdering;
|
|
3812
|
+
if (legacyInterceptorReqResOrdering) {
|
|
3813
|
+
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
|
3814
|
+
} else {
|
|
3815
|
+
requestInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
|
3816
|
+
}
|
|
2510
3817
|
});
|
|
2511
3818
|
const responseInterceptorChain = [];
|
|
2512
3819
|
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
|
@@ -2552,34 +3859,40 @@ let Axios$1 = class Axios {
|
|
|
2552
3859
|
}
|
|
2553
3860
|
getUri(config2) {
|
|
2554
3861
|
config2 = mergeConfig$1(this.defaults, config2);
|
|
2555
|
-
const fullPath = buildFullPath(config2.baseURL, config2.url, config2.allowAbsoluteUrls);
|
|
3862
|
+
const fullPath = buildFullPath(config2.baseURL, config2.url, config2.allowAbsoluteUrls, config2);
|
|
2556
3863
|
return buildURL(fullPath, config2.params, config2.paramsSerializer);
|
|
2557
3864
|
}
|
|
2558
3865
|
};
|
|
2559
3866
|
utils$1.forEach(["delete", "get", "head", "options"], function forEachMethodNoData(method) {
|
|
2560
3867
|
Axios$1.prototype[method] = function(url, config2) {
|
|
2561
|
-
return this.request(
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
3868
|
+
return this.request(
|
|
3869
|
+
mergeConfig$1(config2 || {}, {
|
|
3870
|
+
method,
|
|
3871
|
+
url,
|
|
3872
|
+
data: config2 && utils$1.hasOwnProp(config2, "data") ? config2.data : void 0
|
|
3873
|
+
})
|
|
3874
|
+
);
|
|
2566
3875
|
};
|
|
2567
3876
|
});
|
|
2568
|
-
utils$1.forEach(["post", "put", "patch"], function forEachMethodWithData(method) {
|
|
3877
|
+
utils$1.forEach(["post", "put", "patch", "query"], function forEachMethodWithData(method) {
|
|
2569
3878
|
function generateHTTPMethod(isForm) {
|
|
2570
3879
|
return function httpMethod(url, data, config2) {
|
|
2571
|
-
return this.request(
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
3880
|
+
return this.request(
|
|
3881
|
+
mergeConfig$1(config2 || {}, {
|
|
3882
|
+
method,
|
|
3883
|
+
headers: isForm ? {
|
|
3884
|
+
"Content-Type": "multipart/form-data"
|
|
3885
|
+
} : {},
|
|
3886
|
+
url,
|
|
3887
|
+
data
|
|
3888
|
+
})
|
|
3889
|
+
);
|
|
2579
3890
|
};
|
|
2580
3891
|
}
|
|
2581
3892
|
Axios$1.prototype[method] = generateHTTPMethod();
|
|
2582
|
-
|
|
3893
|
+
if (method !== "query") {
|
|
3894
|
+
Axios$1.prototype[method + "Form"] = generateHTTPMethod(true);
|
|
3895
|
+
}
|
|
2583
3896
|
});
|
|
2584
3897
|
let CancelToken$1 = class CancelToken {
|
|
2585
3898
|
constructor(executor) {
|
|
@@ -2747,7 +4060,13 @@ const HttpStatusCode$1 = {
|
|
|
2747
4060
|
InsufficientStorage: 507,
|
|
2748
4061
|
LoopDetected: 508,
|
|
2749
4062
|
NotExtended: 510,
|
|
2750
|
-
NetworkAuthenticationRequired: 511
|
|
4063
|
+
NetworkAuthenticationRequired: 511,
|
|
4064
|
+
WebServerIsDown: 521,
|
|
4065
|
+
ConnectionTimedOut: 522,
|
|
4066
|
+
OriginIsUnreachable: 523,
|
|
4067
|
+
TimeoutOccurred: 524,
|
|
4068
|
+
SslHandshakeFailed: 525,
|
|
4069
|
+
InvalidSslCertificate: 526
|
|
2751
4070
|
};
|
|
2752
4071
|
Object.entries(HttpStatusCode$1).forEach(([key, value]) => {
|
|
2753
4072
|
HttpStatusCode$1[value] = key;
|
|
@@ -2757,7 +4076,7 @@ function createInstance(defaultConfig) {
|
|
|
2757
4076
|
const instance = bind(Axios$1.prototype.request, context);
|
|
2758
4077
|
utils$1.extend(instance, Axios$1.prototype, context, { allOwnKeys: true });
|
|
2759
4078
|
utils$1.extend(instance, context, null, { allOwnKeys: true });
|
|
2760
|
-
instance.create = function
|
|
4079
|
+
instance.create = function create2(instanceConfig) {
|
|
2761
4080
|
return createInstance(mergeConfig$1(defaultConfig, instanceConfig));
|
|
2762
4081
|
};
|
|
2763
4082
|
return instance;
|
|
@@ -2784,8 +4103,8 @@ axios.HttpStatusCode = HttpStatusCode$1;
|
|
|
2784
4103
|
axios.default = axios;
|
|
2785
4104
|
const {
|
|
2786
4105
|
Axios: Axios2,
|
|
2787
|
-
AxiosError,
|
|
2788
|
-
CanceledError,
|
|
4106
|
+
AxiosError: AxiosError2,
|
|
4107
|
+
CanceledError: CanceledError2,
|
|
2789
4108
|
isCancel,
|
|
2790
4109
|
CancelToken: CancelToken2,
|
|
2791
4110
|
VERSION,
|
|
@@ -2798,7 +4117,8 @@ const {
|
|
|
2798
4117
|
HttpStatusCode,
|
|
2799
4118
|
formToJSON,
|
|
2800
4119
|
getAdapter,
|
|
2801
|
-
mergeConfig
|
|
4120
|
+
mergeConfig,
|
|
4121
|
+
create
|
|
2802
4122
|
} = axios;
|
|
2803
4123
|
const service = ({ strapi }) => {
|
|
2804
4124
|
return {
|
|
@@ -2829,29 +4149,6 @@ const service = ({ strapi }) => {
|
|
|
2829
4149
|
async getUsuarios(sanitizedQueryParams) {
|
|
2830
4150
|
return await strapi.documents("plugin::users-permissions.user").findMany(sanitizedQueryParams);
|
|
2831
4151
|
},
|
|
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
4152
|
// ───────────────────────────────
|
|
2856
4153
|
// 📥 Proxy File Download (bypasses browser CORS)
|
|
2857
4154
|
// ───────────────────────────────
|
|
@@ -2889,27 +4186,7 @@ const service = ({ strapi }) => {
|
|
|
2889
4186
|
// 🏞️ Internal File Upload Helper
|
|
2890
4187
|
// ───────────────────────────────
|
|
2891
4188
|
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
|
-
}
|
|
4189
|
+
const folderId = await ensureFolder(strapi, folderName);
|
|
2913
4190
|
let fileSize = 0;
|
|
2914
4191
|
if (typeof file === "string") {
|
|
2915
4192
|
const stats = fs__namespace.statSync(file);
|
|
@@ -3144,15 +4421,7 @@ const service = ({ strapi }) => {
|
|
|
3144
4421
|
output_format: "image/png"
|
|
3145
4422
|
};
|
|
3146
4423
|
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
|
-
);
|
|
4424
|
+
const generatedBase64Image = await strapi.plugin("strapi-content-generator-gemini").service("image-studio").generateForArticle(promptText, aspectRatio || "16:9", imageSize || "1K");
|
|
3156
4425
|
const buffer = Buffer.from(generatedBase64Image, "base64");
|
|
3157
4426
|
const uploadedFile = await this._uploadGeneratedFile(buffer, `article-${articleId}.png`, "image/png");
|
|
3158
4427
|
const articleModel = await strapi.getModel("api::articulo.articulo");
|
|
@@ -3175,134 +4444,10 @@ const service = ({ strapi }) => {
|
|
|
3175
4444
|
throw new Error("Error al generar la imagen para el artículo.");
|
|
3176
4445
|
}
|
|
3177
4446
|
},
|
|
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
4447
|
// 🎞️ Internal Veo Video Generation / Extension Helper
|
|
3303
4448
|
async _callVeoVideoGeneration(promptText, aspectRatio, durationSeconds, sceneRefs, previousVideo) {
|
|
3304
4449
|
const ai = await this.geminiConfig();
|
|
3305
|
-
const
|
|
4450
|
+
const cleanPrompt2 = promptText.replace(/\s+/g, " ").trim();
|
|
3306
4451
|
const referenceImages = sceneRefs.map((img) => ({
|
|
3307
4452
|
image: {
|
|
3308
4453
|
imageBytes: img.buffer.toString("base64"),
|
|
@@ -3319,7 +4464,7 @@ const service = ({ strapi }) => {
|
|
|
3319
4464
|
};
|
|
3320
4465
|
const operationParams = {
|
|
3321
4466
|
model: "veo-3.1-generate-preview",
|
|
3322
|
-
prompt:
|
|
4467
|
+
prompt: cleanPrompt2,
|
|
3323
4468
|
config: config2
|
|
3324
4469
|
};
|
|
3325
4470
|
if (previousVideo) {
|
|
@@ -3551,13 +4696,15 @@ ${hashtags}`,
|
|
|
3551
4696
|
};
|
|
3552
4697
|
};
|
|
3553
4698
|
const services = {
|
|
3554
|
-
service
|
|
4699
|
+
service,
|
|
4700
|
+
"image-studio": imageStudio$1,
|
|
4701
|
+
templates: templates$1
|
|
3555
4702
|
};
|
|
3556
4703
|
const index = {
|
|
3557
4704
|
register,
|
|
3558
4705
|
bootstrap,
|
|
3559
4706
|
destroy,
|
|
3560
|
-
config: config$
|
|
4707
|
+
config: config$2,
|
|
3561
4708
|
controllers,
|
|
3562
4709
|
routes,
|
|
3563
4710
|
services,
|