@interware/content-generator 0.4.3 → 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-oubMDdAZ.mjs → App-DPVBu7QB.mjs} +37 -712
- package/dist/_chunks/{App-DmCOiKrV.js → App-DVTFrZvf.js} +31 -706
- 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-DwDV99gW.js → getTranslation-D88uLXGd.js} +1 -1
- package/dist/_chunks/{getTranslation-B0tfTODk.mjs → getTranslation-DfxaP_TC.mjs} +1 -1
- package/dist/_chunks/{index-PnmqwUfI.mjs → index-CqDdi211.mjs} +25 -7
- package/dist/_chunks/{index-CTnsB_jp.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 +2439 -1247
- package/dist/server/index.mjs +2446 -1253
- 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 +1 -5
- package/dist/server/src/controllers/image-studio.d.ts +23 -0
- package/dist/server/src/controllers/index.d.ts +129 -5
- package/dist/server/src/controllers/templates.d.ts +26 -0
- package/dist/server/src/image-studio/geminiConfig.d.ts +40 -0
- package/dist/server/src/image-studio/models.d.ts +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 +231 -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 +28 -57
- package/dist/server/src/services/service.d.ts +1 -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-APrsjya3.js +0 -262
- package/dist/_chunks/Settings-BevnW4cE.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 -11
- 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,38 +154,14 @@ 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
|
|
128
|
-
|
|
163
|
+
async downloadFile(ctx) {
|
|
164
|
+
await pluginService().downloadFile(ctx);
|
|
129
165
|
},
|
|
130
166
|
async generateVideo(ctx) {
|
|
131
167
|
ctx.body = await pluginService().generateVideo(ctx);
|
|
@@ -135,186 +171,719 @@ const controller = ({ strapi }) => {
|
|
|
135
171
|
},
|
|
136
172
|
async publishToFacebook(ctx) {
|
|
137
173
|
ctx.body = await pluginService().publishToFacebook(ctx);
|
|
138
|
-
},
|
|
139
|
-
async get(ctx) {
|
|
140
|
-
const pluginStore = strapi.store({
|
|
141
|
-
type: "plugin",
|
|
142
|
-
name: "strapi-content-generator-gemini"
|
|
143
|
-
});
|
|
144
|
-
const googleGenAI = await pluginStore.get({ key: "GOOGLE_GEN_AI" });
|
|
145
|
-
const clientURL = await pluginStore.get({ key: "CLIENT_URL" });
|
|
146
|
-
const previewSecret = await pluginStore.get({ key: "PREVIEW_SECRET" });
|
|
147
|
-
ctx.body = { googleGenAI, clientURL, previewSecret };
|
|
148
|
-
},
|
|
149
|
-
async set(ctx) {
|
|
150
|
-
const { key1, key2, key3 } = ctx.request.body;
|
|
151
|
-
const pluginStore = strapi.store({
|
|
152
|
-
type: "plugin",
|
|
153
|
-
name: "strapi-content-generator-gemini"
|
|
154
|
-
});
|
|
155
|
-
await pluginStore.set({ key: "GOOGLE_GEN_AI", value: key1 });
|
|
156
|
-
await pluginStore.set({ key: "CLIENT_URL", value: key2 });
|
|
157
|
-
await pluginStore.set({ key: "PREVIEW_SECRET", value: key3 });
|
|
158
|
-
ctx.body = { ok: true };
|
|
159
174
|
}
|
|
160
175
|
};
|
|
161
176
|
};
|
|
162
|
-
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
|
+
});
|
|
163
196
|
return {
|
|
197
|
+
/** Devuelve si cada credencial está guardada y sus últimos 4 caracteres, nunca el valor. */
|
|
164
198
|
async get(ctx) {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const linkedInAccessToken = await pluginStore.get({ key: "LINKEDIN_ACCESS_TOKEN" });
|
|
171
|
-
const linkedInOrganizationId = await pluginStore.get({ key: "LINKEDIN_ORGANIZATION_ID" });
|
|
172
|
-
const facebookClientToken = await pluginStore.get({ key: "FACEBOOK_CLIENT_TOKEN" });
|
|
173
|
-
const facebookPageId = await pluginStore.get({ key: "FACEBOOK_PAGE_ID" });
|
|
174
|
-
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);
|
|
175
204
|
},
|
|
205
|
+
/** Escribe solo las credenciales conocidas que llegan como texto no vacío. */
|
|
176
206
|
async set(ctx) {
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
await pluginStore.set({ key: "FACEBOOK_CLIENT_TOKEN", value: facebookClientToken });
|
|
186
|
-
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
|
+
}
|
|
187
215
|
ctx.body = { ok: true };
|
|
188
216
|
}
|
|
189
217
|
};
|
|
190
218
|
};
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
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
|
|
194
233
|
};
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
{
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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);
|
|
205
342
|
}
|
|
206
343
|
},
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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;
|
|
215
362
|
},
|
|
216
|
-
{
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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;
|
|
224
377
|
},
|
|
225
|
-
{
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
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);
|
|
233
388
|
},
|
|
234
|
-
{
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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.");
|
|
241
469
|
}
|
|
242
|
-
}
|
|
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 = [
|
|
243
492
|
{
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
+
]
|
|
251
508
|
},
|
|
252
509
|
{
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
+
]
|
|
260
527
|
},
|
|
261
528
|
{
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
+
]
|
|
269
548
|
},
|
|
270
549
|
{
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
+
]
|
|
278
567
|
},
|
|
279
568
|
{
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
+
]
|
|
287
586
|
},
|
|
288
587
|
{
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
+
]
|
|
296
605
|
}
|
|
297
606
|
];
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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);
|
|
306
619
|
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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.");
|
|
315
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] }
|
|
316
855
|
}
|
|
317
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 = [];
|
|
318
887
|
const routes = {
|
|
319
888
|
"content-api": {
|
|
320
889
|
type: "content-api",
|
|
@@ -333,9 +902,26 @@ function bind(fn, thisArg) {
|
|
|
333
902
|
const { toString } = Object.prototype;
|
|
334
903
|
const { getPrototypeOf } = Object;
|
|
335
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;
|
|
336
922
|
const kindOf = /* @__PURE__ */ ((cache) => (thing) => {
|
|
337
|
-
const
|
|
338
|
-
return cache[
|
|
923
|
+
const str2 = toString.call(thing);
|
|
924
|
+
return cache[str2] || (cache[str2] = str2.slice(8, -1).toLowerCase());
|
|
339
925
|
})(/* @__PURE__ */ Object.create(null));
|
|
340
926
|
const kindOfTest = (type) => {
|
|
341
927
|
type = type.toLowerCase();
|
|
@@ -363,11 +949,14 @@ const isNumber = typeOfTest("number");
|
|
|
363
949
|
const isObject = (thing) => thing !== null && typeof thing === "object";
|
|
364
950
|
const isBoolean = (thing) => thing === true || thing === false;
|
|
365
951
|
const isPlainObject = (val) => {
|
|
366
|
-
if (
|
|
952
|
+
if (!isObject(val)) {
|
|
367
953
|
return false;
|
|
368
954
|
}
|
|
369
955
|
const prototype2 = getPrototypeOf(val);
|
|
370
|
-
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);
|
|
371
960
|
};
|
|
372
961
|
const isEmptyObject = (val) => {
|
|
373
962
|
if (!isObject(val) || isBuffer(val)) {
|
|
@@ -381,17 +970,42 @@ const isEmptyObject = (val) => {
|
|
|
381
970
|
};
|
|
382
971
|
const isDate = kindOfTest("Date");
|
|
383
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";
|
|
384
977
|
const isBlob = kindOfTest("Blob");
|
|
385
978
|
const isFileList = kindOfTest("FileList");
|
|
386
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;
|
|
387
989
|
const isFormData = (thing) => {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
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]";
|
|
391
998
|
};
|
|
392
999
|
const isURLSearchParams = kindOfTest("URLSearchParams");
|
|
393
|
-
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
|
394
|
-
|
|
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
|
+
};
|
|
395
1009
|
function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
|
396
1010
|
if (obj === null || typeof obj === "undefined") {
|
|
397
1011
|
return;
|
|
@@ -439,13 +1053,17 @@ const _global = (() => {
|
|
|
439
1053
|
return typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : global;
|
|
440
1054
|
})();
|
|
441
1055
|
const isContextDefined = (context) => !isUndefined(context) && context !== _global;
|
|
442
|
-
function merge() {
|
|
1056
|
+
function merge(...objs) {
|
|
443
1057
|
const { caseless, skipUndefined } = isContextDefined(this) && this || {};
|
|
444
1058
|
const result = {};
|
|
445
1059
|
const assignValue = (val, key) => {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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);
|
|
449
1067
|
} else if (isPlainObject(val)) {
|
|
450
1068
|
result[targetKey] = merge({}, val);
|
|
451
1069
|
} else if (isArray(val)) {
|
|
@@ -454,19 +1072,51 @@ function merge() {
|
|
|
454
1072
|
result[targetKey] = val;
|
|
455
1073
|
}
|
|
456
1074
|
};
|
|
457
|
-
for (let i = 0, l =
|
|
458
|
-
|
|
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
|
+
}
|
|
459
1091
|
}
|
|
460
1092
|
return result;
|
|
461
1093
|
}
|
|
462
1094
|
const extend = (a, b, thisArg, { allOwnKeys } = {}) => {
|
|
463
|
-
forEach(
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
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
|
+
);
|
|
470
1120
|
return a;
|
|
471
1121
|
};
|
|
472
1122
|
const stripBOM = (content) => {
|
|
@@ -475,10 +1125,17 @@ const stripBOM = (content) => {
|
|
|
475
1125
|
}
|
|
476
1126
|
return content;
|
|
477
1127
|
};
|
|
478
|
-
const inherits = (constructor, superConstructor, props,
|
|
479
|
-
constructor.prototype = Object.create(superConstructor.prototype,
|
|
480
|
-
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
|
+
});
|
|
481
1137
|
Object.defineProperty(constructor, "super", {
|
|
1138
|
+
__proto__: null,
|
|
482
1139
|
value: superConstructor.prototype
|
|
483
1140
|
});
|
|
484
1141
|
props && Object.assign(constructor.prototype, props);
|
|
@@ -504,13 +1161,13 @@ const toFlatObject = (sourceObj, destObj, filter2, propFilter) => {
|
|
|
504
1161
|
} while (sourceObj && (!filter2 || filter2(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
|
505
1162
|
return destObj;
|
|
506
1163
|
};
|
|
507
|
-
const endsWith = (
|
|
508
|
-
|
|
509
|
-
if (position === void 0 || position >
|
|
510
|
-
position =
|
|
1164
|
+
const endsWith = (str2, searchString, position) => {
|
|
1165
|
+
str2 = String(str2);
|
|
1166
|
+
if (position === void 0 || position > str2.length) {
|
|
1167
|
+
position = str2.length;
|
|
511
1168
|
}
|
|
512
1169
|
position -= searchString.length;
|
|
513
|
-
const lastIndex =
|
|
1170
|
+
const lastIndex = str2.indexOf(searchString, position);
|
|
514
1171
|
return lastIndex !== -1 && lastIndex === position;
|
|
515
1172
|
};
|
|
516
1173
|
const toArray = (thing) => {
|
|
@@ -538,42 +1195,39 @@ const forEachEntry = (obj, fn) => {
|
|
|
538
1195
|
fn.call(obj, pair[0], pair[1]);
|
|
539
1196
|
}
|
|
540
1197
|
};
|
|
541
|
-
const matchAll = (regExp,
|
|
1198
|
+
const matchAll = (regExp, str2) => {
|
|
542
1199
|
let matches;
|
|
543
1200
|
const arr = [];
|
|
544
|
-
while ((matches = regExp.exec(
|
|
1201
|
+
while ((matches = regExp.exec(str2)) !== null) {
|
|
545
1202
|
arr.push(matches);
|
|
546
1203
|
}
|
|
547
1204
|
return arr;
|
|
548
1205
|
};
|
|
549
1206
|
const isHTMLForm = kindOfTest("HTMLFormElement");
|
|
550
|
-
const toCamelCase = (
|
|
551
|
-
return
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
return p1.toUpperCase() + p2;
|
|
555
|
-
}
|
|
556
|
-
);
|
|
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
|
+
});
|
|
557
1211
|
};
|
|
558
|
-
const
|
|
1212
|
+
const { propertyIsEnumerable } = Object.prototype;
|
|
559
1213
|
const isRegExp = kindOfTest("RegExp");
|
|
560
1214
|
const reduceDescriptors = (obj, reducer) => {
|
|
561
|
-
const
|
|
1215
|
+
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
|
562
1216
|
const reducedDescriptors = {};
|
|
563
|
-
forEach(
|
|
1217
|
+
forEach(descriptors, (descriptor, name2) => {
|
|
564
1218
|
let ret;
|
|
565
|
-
if ((ret = reducer(descriptor,
|
|
566
|
-
reducedDescriptors[
|
|
1219
|
+
if ((ret = reducer(descriptor, name2, obj)) !== false) {
|
|
1220
|
+
reducedDescriptors[name2] = ret || descriptor;
|
|
567
1221
|
}
|
|
568
1222
|
});
|
|
569
1223
|
Object.defineProperties(obj, reducedDescriptors);
|
|
570
1224
|
};
|
|
571
1225
|
const freezeMethods = (obj) => {
|
|
572
|
-
reduceDescriptors(obj, (descriptor,
|
|
573
|
-
if (isFunction$1(obj) && ["arguments", "caller", "callee"].
|
|
1226
|
+
reduceDescriptors(obj, (descriptor, name2) => {
|
|
1227
|
+
if (isFunction$1(obj) && ["arguments", "caller", "callee"].includes(name2)) {
|
|
574
1228
|
return false;
|
|
575
1229
|
}
|
|
576
|
-
const value = obj[
|
|
1230
|
+
const value = obj[name2];
|
|
577
1231
|
if (!isFunction$1(value)) return;
|
|
578
1232
|
descriptor.enumerable = false;
|
|
579
1233
|
if ("writable" in descriptor) {
|
|
@@ -582,7 +1236,7 @@ const freezeMethods = (obj) => {
|
|
|
582
1236
|
}
|
|
583
1237
|
if (!descriptor.set) {
|
|
584
1238
|
descriptor.set = () => {
|
|
585
|
-
throw Error("Can not rewrite read-only method '" +
|
|
1239
|
+
throw Error("Can not rewrite read-only method '" + name2 + "'");
|
|
586
1240
|
};
|
|
587
1241
|
}
|
|
588
1242
|
});
|
|
@@ -606,29 +1260,29 @@ function isSpecCompliantForm(thing) {
|
|
|
606
1260
|
return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === "FormData" && thing[iterator]);
|
|
607
1261
|
}
|
|
608
1262
|
const toJSONObject = (obj) => {
|
|
609
|
-
const
|
|
610
|
-
const visit = (source
|
|
1263
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
1264
|
+
const visit = (source) => {
|
|
611
1265
|
if (isObject(source)) {
|
|
612
|
-
if (
|
|
1266
|
+
if (visited.has(source)) {
|
|
613
1267
|
return;
|
|
614
1268
|
}
|
|
615
1269
|
if (isBuffer(source)) {
|
|
616
1270
|
return source;
|
|
617
1271
|
}
|
|
618
1272
|
if (!("toJSON" in source)) {
|
|
619
|
-
|
|
1273
|
+
visited.add(source);
|
|
620
1274
|
const target = isArray(source) ? [] : {};
|
|
621
1275
|
forEach(source, (value, key) => {
|
|
622
|
-
const reducedValue = visit(value
|
|
1276
|
+
const reducedValue = visit(value);
|
|
623
1277
|
!isUndefined(reducedValue) && (target[key] = reducedValue);
|
|
624
1278
|
});
|
|
625
|
-
|
|
1279
|
+
visited.delete(source);
|
|
626
1280
|
return target;
|
|
627
1281
|
}
|
|
628
1282
|
}
|
|
629
1283
|
return source;
|
|
630
1284
|
};
|
|
631
|
-
return visit(obj
|
|
1285
|
+
return visit(obj);
|
|
632
1286
|
};
|
|
633
1287
|
const isAsyncFn = kindOfTest("AsyncFunction");
|
|
634
1288
|
const isThenable = (thing) => thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
|
|
@@ -637,22 +1291,24 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
|
|
637
1291
|
return setImmediate;
|
|
638
1292
|
}
|
|
639
1293
|
return postMessageSupported ? ((token, callbacks) => {
|
|
640
|
-
_global.addEventListener(
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
1294
|
+
_global.addEventListener(
|
|
1295
|
+
"message",
|
|
1296
|
+
({ source, data }) => {
|
|
1297
|
+
if (source === _global && data === token) {
|
|
1298
|
+
callbacks.length && callbacks.shift()();
|
|
1299
|
+
}
|
|
1300
|
+
},
|
|
1301
|
+
false
|
|
1302
|
+
);
|
|
645
1303
|
return (cb) => {
|
|
646
1304
|
callbacks.push(cb);
|
|
647
1305
|
_global.postMessage(token, "*");
|
|
648
1306
|
};
|
|
649
1307
|
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
|
650
|
-
})(
|
|
651
|
-
typeof setImmediate === "function",
|
|
652
|
-
isFunction$1(_global.postMessage)
|
|
653
|
-
);
|
|
1308
|
+
})(typeof setImmediate === "function", isFunction$1(_global.postMessage));
|
|
654
1309
|
const asap = typeof queueMicrotask !== "undefined" ? queueMicrotask.bind(_global) : typeof process !== "undefined" && process.nextTick || _setImmediate;
|
|
655
1310
|
const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
|
|
1311
|
+
const isSafeIterable = (thing) => thing != null && hasOwnInPrototypeChain(thing, iterator) && isIterable(thing);
|
|
656
1312
|
const utils$1 = {
|
|
657
1313
|
isArray,
|
|
658
1314
|
isArrayBuffer,
|
|
@@ -672,6 +1328,8 @@ const utils$1 = {
|
|
|
672
1328
|
isUndefined,
|
|
673
1329
|
isDate,
|
|
674
1330
|
isFile,
|
|
1331
|
+
isReactNativeBlob,
|
|
1332
|
+
isReactNative,
|
|
675
1333
|
isBlob,
|
|
676
1334
|
isRegExp,
|
|
677
1335
|
isFunction: isFunction$1,
|
|
@@ -696,6 +1354,8 @@ const utils$1 = {
|
|
|
696
1354
|
hasOwnProperty,
|
|
697
1355
|
hasOwnProp: hasOwnProperty,
|
|
698
1356
|
// an alias to avoid ESLint no-prototype-builtins detection
|
|
1357
|
+
hasOwnInPrototypeChain,
|
|
1358
|
+
getSafeProp,
|
|
699
1359
|
reduceDescriptors,
|
|
700
1360
|
freezeMethods,
|
|
701
1361
|
toObjectSet,
|
|
@@ -711,98 +1371,483 @@ const utils$1 = {
|
|
|
711
1371
|
isThenable,
|
|
712
1372
|
setImmediate: _setImmediate,
|
|
713
1373
|
asap,
|
|
714
|
-
isIterable
|
|
715
|
-
|
|
716
|
-
function AxiosError$1(message, code, config2, request, response) {
|
|
717
|
-
Error.call(this);
|
|
718
|
-
if (Error.captureStackTrace) {
|
|
719
|
-
Error.captureStackTrace(this, this.constructor);
|
|
720
|
-
} else {
|
|
721
|
-
this.stack = new Error().stack;
|
|
722
|
-
}
|
|
723
|
-
this.message = message;
|
|
724
|
-
this.name = "AxiosError";
|
|
725
|
-
code && (this.code = code);
|
|
726
|
-
config2 && (this.config = config2);
|
|
727
|
-
request && (this.request = request);
|
|
728
|
-
if (response) {
|
|
729
|
-
this.response = response;
|
|
730
|
-
this.status = response.status ? response.status : null;
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
utils$1.inherits(AxiosError$1, Error, {
|
|
734
|
-
toJSON: function toJSON() {
|
|
735
|
-
return {
|
|
736
|
-
// Standard
|
|
737
|
-
message: this.message,
|
|
738
|
-
name: this.name,
|
|
739
|
-
// Microsoft
|
|
740
|
-
description: this.description,
|
|
741
|
-
number: this.number,
|
|
742
|
-
// Mozilla
|
|
743
|
-
fileName: this.fileName,
|
|
744
|
-
lineNumber: this.lineNumber,
|
|
745
|
-
columnNumber: this.columnNumber,
|
|
746
|
-
stack: this.stack,
|
|
747
|
-
// Axios
|
|
748
|
-
config: utils$1.toJSONObject(this.config),
|
|
749
|
-
code: this.code,
|
|
750
|
-
status: this.status
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
});
|
|
754
|
-
const prototype$1 = AxiosError$1.prototype;
|
|
755
|
-
const descriptors = {};
|
|
756
|
-
[
|
|
757
|
-
"ERR_BAD_OPTION_VALUE",
|
|
758
|
-
"ERR_BAD_OPTION",
|
|
759
|
-
"ECONNABORTED",
|
|
760
|
-
"ETIMEDOUT",
|
|
761
|
-
"ERR_NETWORK",
|
|
762
|
-
"ERR_FR_TOO_MANY_REDIRECTS",
|
|
763
|
-
"ERR_DEPRECATED",
|
|
764
|
-
"ERR_BAD_RESPONSE",
|
|
765
|
-
"ERR_BAD_REQUEST",
|
|
766
|
-
"ERR_CANCELED",
|
|
767
|
-
"ERR_NOT_SUPPORT",
|
|
768
|
-
"ERR_INVALID_URL"
|
|
769
|
-
// eslint-disable-next-line func-names
|
|
770
|
-
].forEach((code) => {
|
|
771
|
-
descriptors[code] = { value: code };
|
|
772
|
-
});
|
|
773
|
-
Object.defineProperties(AxiosError$1, descriptors);
|
|
774
|
-
Object.defineProperty(prototype$1, "isAxiosError", { value: true });
|
|
775
|
-
AxiosError$1.from = (error, code, config2, request, response, customProps) => {
|
|
776
|
-
const axiosError = Object.create(prototype$1);
|
|
777
|
-
utils$1.toFlatObject(error, axiosError, function filter2(obj) {
|
|
778
|
-
return obj !== Error.prototype;
|
|
779
|
-
}, (prop) => {
|
|
780
|
-
return prop !== "isAxiosError";
|
|
781
|
-
});
|
|
782
|
-
const msg = error && error.message ? error.message : "Error";
|
|
783
|
-
const errCode = code == null && error ? error.code : code;
|
|
784
|
-
AxiosError$1.call(axiosError, msg, errCode, config2, request, response);
|
|
785
|
-
if (error && axiosError.cause == null) {
|
|
786
|
-
Object.defineProperty(axiosError, "cause", { value: error, configurable: true });
|
|
787
|
-
}
|
|
788
|
-
axiosError.name = error && error.name || "Error";
|
|
789
|
-
customProps && Object.assign(axiosError, customProps);
|
|
790
|
-
return axiosError;
|
|
1374
|
+
isIterable,
|
|
1375
|
+
isSafeIterable
|
|
791
1376
|
};
|
|
792
|
-
const
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
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) {
|
|
1847
|
+
token = removeBrackets(token);
|
|
1848
|
+
return !dots && i ? "[" + token + "]" : token;
|
|
1849
|
+
}).join(dots ? "." : "");
|
|
1850
|
+
}
|
|
806
1851
|
function isFlatArray(arr) {
|
|
807
1852
|
return utils$1.isArray(arr) && !arr.some(isVisitable);
|
|
808
1853
|
}
|
|
@@ -814,19 +1859,26 @@ function toFormData$1(obj, formData, options) {
|
|
|
814
1859
|
throw new TypeError("target must be an object");
|
|
815
1860
|
}
|
|
816
1861
|
formData = formData || new FormData();
|
|
817
|
-
options = utils$1.toFlatObject(
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
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
|
+
);
|
|
824
1874
|
const metaTokens = options.metaTokens;
|
|
825
1875
|
const visitor = options.visitor || defaultVisitor;
|
|
826
1876
|
const dots = options.dots;
|
|
827
1877
|
const indexes = options.indexes;
|
|
828
1878
|
const _Blob = options.Blob || typeof Blob !== "undefined" && Blob;
|
|
1879
|
+
const maxDepth = options.maxDepth === void 0 ? DEFAULT_FORM_DATA_MAX_DEPTH : options.maxDepth;
|
|
829
1880
|
const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
|
|
1881
|
+
const stack = [];
|
|
830
1882
|
if (!utils$1.isFunction(visitor)) {
|
|
831
1883
|
throw new TypeError("visitor must be a function");
|
|
832
1884
|
}
|
|
@@ -842,16 +1894,51 @@ function toFormData$1(obj, formData, options) {
|
|
|
842
1894
|
throw new AxiosError$1("Blob is not supported. Use a Buffer instead.");
|
|
843
1895
|
}
|
|
844
1896
|
if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
|
|
845
|
-
|
|
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);
|
|
846
1904
|
}
|
|
847
1905
|
return value;
|
|
848
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
|
+
}
|
|
849
1932
|
function defaultVisitor(value, key, path) {
|
|
850
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
|
+
}
|
|
851
1938
|
if (value && !path && typeof value === "object") {
|
|
852
1939
|
if (utils$1.endsWith(key, "{}")) {
|
|
853
1940
|
key = metaTokens ? key : key.slice(0, -2);
|
|
854
|
-
value =
|
|
1941
|
+
value = stringifyWithDepthLimit(value, 1);
|
|
855
1942
|
} else if (utils$1.isArray(value) && isFlatArray(value) || (utils$1.isFileList(value) || utils$1.endsWith(key, "[]")) && (arr = utils$1.toArray(value))) {
|
|
856
1943
|
key = removeBrackets(key);
|
|
857
1944
|
arr.forEach(function each(el, index2) {
|
|
@@ -870,28 +1957,22 @@ function toFormData$1(obj, formData, options) {
|
|
|
870
1957
|
formData.append(renderKey(path, key, dots), convertValue(value));
|
|
871
1958
|
return false;
|
|
872
1959
|
}
|
|
873
|
-
const stack = [];
|
|
874
1960
|
const exposedHelpers = Object.assign(predicates, {
|
|
875
1961
|
defaultVisitor,
|
|
876
1962
|
convertValue,
|
|
877
1963
|
isVisitable
|
|
878
1964
|
});
|
|
879
|
-
function build(value, path) {
|
|
1965
|
+
function build(value, path, depth = 0) {
|
|
880
1966
|
if (utils$1.isUndefined(value)) return;
|
|
1967
|
+
throwIfMaxDepthExceeded(depth);
|
|
881
1968
|
if (stack.indexOf(value) !== -1) {
|
|
882
|
-
throw Error("Circular reference detected in " + path.join("."));
|
|
1969
|
+
throw new Error("Circular reference detected in " + path.join("."));
|
|
883
1970
|
}
|
|
884
1971
|
stack.push(value);
|
|
885
1972
|
utils$1.forEach(value, function each(el, key) {
|
|
886
|
-
const result = !(utils$1.isUndefined(el) || el === null) && visitor.call(
|
|
887
|
-
formData,
|
|
888
|
-
el,
|
|
889
|
-
utils$1.isString(key) ? key.trim() : key,
|
|
890
|
-
path,
|
|
891
|
-
exposedHelpers
|
|
892
|
-
);
|
|
1973
|
+
const result = !(utils$1.isUndefined(el) || el === null) && visitor.call(formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers);
|
|
893
1974
|
if (result === true) {
|
|
894
|
-
build(el, path ? path.concat(key) : [key]);
|
|
1975
|
+
build(el, path ? path.concat(key) : [key], depth + 1);
|
|
895
1976
|
}
|
|
896
1977
|
});
|
|
897
1978
|
stack.pop();
|
|
@@ -902,17 +1983,16 @@ function toFormData$1(obj, formData, options) {
|
|
|
902
1983
|
build(obj);
|
|
903
1984
|
return formData;
|
|
904
1985
|
}
|
|
905
|
-
function encode$1(
|
|
1986
|
+
function encode$1(str2) {
|
|
906
1987
|
const charMap = {
|
|
907
1988
|
"!": "%21",
|
|
908
1989
|
"'": "%27",
|
|
909
1990
|
"(": "%28",
|
|
910
1991
|
")": "%29",
|
|
911
1992
|
"~": "%7E",
|
|
912
|
-
"%20": "+"
|
|
913
|
-
"%00": "\0"
|
|
1993
|
+
"%20": "+"
|
|
914
1994
|
};
|
|
915
|
-
return encodeURIComponent(
|
|
1995
|
+
return encodeURIComponent(str2).replace(/[!'()~]|%20/g, function replacer(match) {
|
|
916
1996
|
return charMap[match];
|
|
917
1997
|
});
|
|
918
1998
|
}
|
|
@@ -921,13 +2001,11 @@ function AxiosURLSearchParams(params, options) {
|
|
|
921
2001
|
params && toFormData$1(params, this, options);
|
|
922
2002
|
}
|
|
923
2003
|
const prototype = AxiosURLSearchParams.prototype;
|
|
924
|
-
prototype.append = function append(
|
|
925
|
-
this._pairs.push([
|
|
2004
|
+
prototype.append = function append(name2, value) {
|
|
2005
|
+
this._pairs.push([name2, value]);
|
|
926
2006
|
};
|
|
927
2007
|
prototype.toString = function toString2(encoder) {
|
|
928
|
-
const _encode = encoder ?
|
|
929
|
-
return encoder.call(this, value, encode$1);
|
|
930
|
-
} : encode$1;
|
|
2008
|
+
const _encode = encoder ? (value) => encoder.call(this, value, encode$1) : encode$1;
|
|
931
2009
|
return this._pairs.map(function each(pair) {
|
|
932
2010
|
return _encode(pair[0]) + "=" + _encode(pair[1]);
|
|
933
2011
|
}, "").join("&");
|
|
@@ -939,18 +2017,17 @@ function buildURL(url, params, options) {
|
|
|
939
2017
|
if (!params) {
|
|
940
2018
|
return url;
|
|
941
2019
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
options
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
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");
|
|
949
2026
|
let serializedParams;
|
|
950
2027
|
if (serializeFn) {
|
|
951
|
-
serializedParams = serializeFn(params,
|
|
2028
|
+
serializedParams = serializeFn(params, _options);
|
|
952
2029
|
} else {
|
|
953
|
-
serializedParams = utils$1.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params,
|
|
2030
|
+
serializedParams = utils$1.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params, _options).toString(_encode);
|
|
954
2031
|
}
|
|
955
2032
|
if (serializedParams) {
|
|
956
2033
|
const hashmarkIndex = url.indexOf("#");
|
|
@@ -970,6 +2047,7 @@ class InterceptorManager {
|
|
|
970
2047
|
*
|
|
971
2048
|
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
|
972
2049
|
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
|
2050
|
+
* @param {Object} options The options for the interceptor, synchronous and runWhen
|
|
973
2051
|
*
|
|
974
2052
|
* @return {Number} An ID used to remove interceptor later
|
|
975
2053
|
*/
|
|
@@ -987,7 +2065,7 @@ class InterceptorManager {
|
|
|
987
2065
|
*
|
|
988
2066
|
* @param {Number} id The ID that was returned by `use`
|
|
989
2067
|
*
|
|
990
|
-
* @returns {
|
|
2068
|
+
* @returns {void}
|
|
991
2069
|
*/
|
|
992
2070
|
eject(id) {
|
|
993
2071
|
if (this.handlers[id]) {
|
|
@@ -1025,7 +2103,10 @@ class InterceptorManager {
|
|
|
1025
2103
|
const transitionalDefaults = {
|
|
1026
2104
|
silentJSONParsing: true,
|
|
1027
2105
|
forcedJSONParsing: true,
|
|
1028
|
-
clarifyTimeoutError: false
|
|
2106
|
+
clarifyTimeoutError: false,
|
|
2107
|
+
legacyInterceptorReqResOrdering: true,
|
|
2108
|
+
advertiseZstdAcceptEncoding: false,
|
|
2109
|
+
validateStatusUndefinedResolves: true
|
|
1029
2110
|
};
|
|
1030
2111
|
const URLSearchParams$1 = typeof URLSearchParams !== "undefined" ? URLSearchParams : AxiosURLSearchParams;
|
|
1031
2112
|
const FormData$1 = typeof FormData !== "undefined" ? FormData : null;
|
|
@@ -1066,436 +2147,190 @@ function toURLEncodedForm(data, options) {
|
|
|
1066
2147
|
this.append(key, value.toString("base64"));
|
|
1067
2148
|
return false;
|
|
1068
2149
|
}
|
|
1069
|
-
return helpers.defaultVisitor.apply(this, arguments);
|
|
1070
|
-
},
|
|
1071
|
-
...options
|
|
1072
|
-
});
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
const keys = Object.keys(arr);
|
|
1082
|
-
let i;
|
|
1083
|
-
const len = keys.length;
|
|
1084
|
-
let key;
|
|
1085
|
-
for (i = 0; i < len; i++) {
|
|
1086
|
-
key = keys[i];
|
|
1087
|
-
obj[key] = arr[key];
|
|
1088
|
-
}
|
|
1089
|
-
return obj;
|
|
1090
|
-
}
|
|
1091
|
-
function formDataToJSON(formData) {
|
|
1092
|
-
function buildPath(path, value, target, index2) {
|
|
1093
|
-
let name = path[index2++];
|
|
1094
|
-
if (name === "__proto__") return true;
|
|
1095
|
-
const isNumericKey = Number.isFinite(+name);
|
|
1096
|
-
const isLast = index2 >= path.length;
|
|
1097
|
-
name = !name && utils$1.isArray(target) ? target.length : name;
|
|
1098
|
-
if (isLast) {
|
|
1099
|
-
if (utils$1.hasOwnProp(target, name)) {
|
|
1100
|
-
target[name] = [target[name], value];
|
|
1101
|
-
} else {
|
|
1102
|
-
target[name] = value;
|
|
1103
|
-
}
|
|
1104
|
-
return !isNumericKey;
|
|
1105
|
-
}
|
|
1106
|
-
if (!target[name] || !utils$1.isObject(target[name])) {
|
|
1107
|
-
target[name] = [];
|
|
1108
|
-
}
|
|
1109
|
-
const result = buildPath(path, value, target[name], index2);
|
|
1110
|
-
if (result && utils$1.isArray(target[name])) {
|
|
1111
|
-
target[name] = arrayToObject(target[name]);
|
|
1112
|
-
}
|
|
1113
|
-
return !isNumericKey;
|
|
1114
|
-
}
|
|
1115
|
-
if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
|
|
1116
|
-
const obj = {};
|
|
1117
|
-
utils$1.forEachEntry(formData, (name, value) => {
|
|
1118
|
-
buildPath(parsePropPath(name), value, obj, 0);
|
|
1119
|
-
});
|
|
1120
|
-
return obj;
|
|
1121
|
-
}
|
|
1122
|
-
return null;
|
|
1123
|
-
}
|
|
1124
|
-
function stringifySafely(rawValue, parser, encoder) {
|
|
1125
|
-
if (utils$1.isString(rawValue)) {
|
|
1126
|
-
try {
|
|
1127
|
-
(parser || JSON.parse)(rawValue);
|
|
1128
|
-
return utils$1.trim(rawValue);
|
|
1129
|
-
} catch (e) {
|
|
1130
|
-
if (e.name !== "SyntaxError") {
|
|
1131
|
-
throw e;
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
return (encoder || JSON.stringify)(rawValue);
|
|
1136
|
-
}
|
|
1137
|
-
const defaults = {
|
|
1138
|
-
transitional: transitionalDefaults,
|
|
1139
|
-
adapter: ["xhr", "http", "fetch"],
|
|
1140
|
-
transformRequest: [function transformRequest(data, headers) {
|
|
1141
|
-
const contentType = headers.getContentType() || "";
|
|
1142
|
-
const hasJSONContentType = contentType.indexOf("application/json") > -1;
|
|
1143
|
-
const isObjectPayload = utils$1.isObject(data);
|
|
1144
|
-
if (isObjectPayload && utils$1.isHTMLForm(data)) {
|
|
1145
|
-
data = new FormData(data);
|
|
1146
|
-
}
|
|
1147
|
-
const isFormData2 = utils$1.isFormData(data);
|
|
1148
|
-
if (isFormData2) {
|
|
1149
|
-
return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
|
|
1150
|
-
}
|
|
1151
|
-
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)) {
|
|
1152
|
-
return data;
|
|
1153
|
-
}
|
|
1154
|
-
if (utils$1.isArrayBufferView(data)) {
|
|
1155
|
-
return data.buffer;
|
|
1156
|
-
}
|
|
1157
|
-
if (utils$1.isURLSearchParams(data)) {
|
|
1158
|
-
headers.setContentType("application/x-www-form-urlencoded;charset=utf-8", false);
|
|
1159
|
-
return data.toString();
|
|
1160
|
-
}
|
|
1161
|
-
let isFileList2;
|
|
1162
|
-
if (isObjectPayload) {
|
|
1163
|
-
if (contentType.indexOf("application/x-www-form-urlencoded") > -1) {
|
|
1164
|
-
return toURLEncodedForm(data, this.formSerializer).toString();
|
|
1165
|
-
}
|
|
1166
|
-
if ((isFileList2 = utils$1.isFileList(data)) || contentType.indexOf("multipart/form-data") > -1) {
|
|
1167
|
-
const _FormData = this.env && this.env.FormData;
|
|
1168
|
-
return toFormData$1(
|
|
1169
|
-
isFileList2 ? { "files[]": data } : data,
|
|
1170
|
-
_FormData && new _FormData(),
|
|
1171
|
-
this.formSerializer
|
|
1172
|
-
);
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
if (isObjectPayload || hasJSONContentType) {
|
|
1176
|
-
headers.setContentType("application/json", false);
|
|
1177
|
-
return stringifySafely(data);
|
|
1178
|
-
}
|
|
1179
|
-
return data;
|
|
1180
|
-
}],
|
|
1181
|
-
transformResponse: [function transformResponse(data) {
|
|
1182
|
-
const transitional2 = this.transitional || defaults.transitional;
|
|
1183
|
-
const forcedJSONParsing = transitional2 && transitional2.forcedJSONParsing;
|
|
1184
|
-
const JSONRequested = this.responseType === "json";
|
|
1185
|
-
if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
|
|
1186
|
-
return data;
|
|
1187
|
-
}
|
|
1188
|
-
if (data && utils$1.isString(data) && (forcedJSONParsing && !this.responseType || JSONRequested)) {
|
|
1189
|
-
const silentJSONParsing = transitional2 && transitional2.silentJSONParsing;
|
|
1190
|
-
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
|
1191
|
-
try {
|
|
1192
|
-
return JSON.parse(data, this.parseReviver);
|
|
1193
|
-
} catch (e) {
|
|
1194
|
-
if (strictJSONParsing) {
|
|
1195
|
-
if (e.name === "SyntaxError") {
|
|
1196
|
-
throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_RESPONSE, this, null, this.response);
|
|
1197
|
-
}
|
|
1198
|
-
throw e;
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
return data;
|
|
1203
|
-
}],
|
|
1204
|
-
/**
|
|
1205
|
-
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
|
1206
|
-
* timeout is not created.
|
|
1207
|
-
*/
|
|
1208
|
-
timeout: 0,
|
|
1209
|
-
xsrfCookieName: "XSRF-TOKEN",
|
|
1210
|
-
xsrfHeaderName: "X-XSRF-TOKEN",
|
|
1211
|
-
maxContentLength: -1,
|
|
1212
|
-
maxBodyLength: -1,
|
|
1213
|
-
env: {
|
|
1214
|
-
FormData: platform.classes.FormData,
|
|
1215
|
-
Blob: platform.classes.Blob
|
|
1216
|
-
},
|
|
1217
|
-
validateStatus: function validateStatus(status) {
|
|
1218
|
-
return status >= 200 && status < 300;
|
|
1219
|
-
},
|
|
1220
|
-
headers: {
|
|
1221
|
-
common: {
|
|
1222
|
-
"Accept": "application/json, text/plain, */*",
|
|
1223
|
-
"Content-Type": void 0
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
};
|
|
1227
|
-
utils$1.forEach(["delete", "get", "head", "post", "put", "patch"], (method) => {
|
|
1228
|
-
defaults.headers[method] = {};
|
|
1229
|
-
});
|
|
1230
|
-
const ignoreDuplicateOf = utils$1.toObjectSet([
|
|
1231
|
-
"age",
|
|
1232
|
-
"authorization",
|
|
1233
|
-
"content-length",
|
|
1234
|
-
"content-type",
|
|
1235
|
-
"etag",
|
|
1236
|
-
"expires",
|
|
1237
|
-
"from",
|
|
1238
|
-
"host",
|
|
1239
|
-
"if-modified-since",
|
|
1240
|
-
"if-unmodified-since",
|
|
1241
|
-
"last-modified",
|
|
1242
|
-
"location",
|
|
1243
|
-
"max-forwards",
|
|
1244
|
-
"proxy-authorization",
|
|
1245
|
-
"referer",
|
|
1246
|
-
"retry-after",
|
|
1247
|
-
"user-agent"
|
|
1248
|
-
]);
|
|
1249
|
-
const parseHeaders = (rawHeaders) => {
|
|
1250
|
-
const parsed = {};
|
|
1251
|
-
let key;
|
|
1252
|
-
let val;
|
|
1253
|
-
let i;
|
|
1254
|
-
rawHeaders && rawHeaders.split("\n").forEach(function parser(line) {
|
|
1255
|
-
i = line.indexOf(":");
|
|
1256
|
-
key = line.substring(0, i).trim().toLowerCase();
|
|
1257
|
-
val = line.substring(i + 1).trim();
|
|
1258
|
-
if (!key || parsed[key] && ignoreDuplicateOf[key]) {
|
|
1259
|
-
return;
|
|
1260
|
-
}
|
|
1261
|
-
if (key === "set-cookie") {
|
|
1262
|
-
if (parsed[key]) {
|
|
1263
|
-
parsed[key].push(val);
|
|
1264
|
-
} else {
|
|
1265
|
-
parsed[key] = [val];
|
|
1266
|
-
}
|
|
1267
|
-
} else {
|
|
1268
|
-
parsed[key] = parsed[key] ? parsed[key] + ", " + val : val;
|
|
1269
|
-
}
|
|
1270
|
-
});
|
|
1271
|
-
return parsed;
|
|
1272
|
-
};
|
|
1273
|
-
const $internals = Symbol("internals");
|
|
1274
|
-
function normalizeHeader(header) {
|
|
1275
|
-
return header && String(header).trim().toLowerCase();
|
|
1276
|
-
}
|
|
1277
|
-
function normalizeValue(value) {
|
|
1278
|
-
if (value === false || value == null) {
|
|
1279
|
-
return value;
|
|
1280
|
-
}
|
|
1281
|
-
return utils$1.isArray(value) ? value.map(normalizeValue) : String(value);
|
|
1282
|
-
}
|
|
1283
|
-
function parseTokens(str) {
|
|
1284
|
-
const tokens = /* @__PURE__ */ Object.create(null);
|
|
1285
|
-
const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
|
|
1286
|
-
let match;
|
|
1287
|
-
while (match = tokensRE.exec(str)) {
|
|
1288
|
-
tokens[match[1]] = match[2];
|
|
1289
|
-
}
|
|
1290
|
-
return tokens;
|
|
1291
|
-
}
|
|
1292
|
-
const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
|
|
1293
|
-
function matchHeaderValue(context, value, header, filter2, isHeaderNameFilter) {
|
|
1294
|
-
if (utils$1.isFunction(filter2)) {
|
|
1295
|
-
return filter2.call(this, value, header);
|
|
1296
|
-
}
|
|
1297
|
-
if (isHeaderNameFilter) {
|
|
1298
|
-
value = header;
|
|
1299
|
-
}
|
|
1300
|
-
if (!utils$1.isString(value)) return;
|
|
1301
|
-
if (utils$1.isString(filter2)) {
|
|
1302
|
-
return value.indexOf(filter2) !== -1;
|
|
1303
|
-
}
|
|
1304
|
-
if (utils$1.isRegExp(filter2)) {
|
|
1305
|
-
return filter2.test(value);
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
function formatHeader(header) {
|
|
1309
|
-
return header.trim().toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
|
|
1310
|
-
return char.toUpperCase() + str;
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
|
-
function buildAccessors(obj, header) {
|
|
1314
|
-
const accessorName = utils$1.toCamelCase(" " + header);
|
|
1315
|
-
["get", "set", "has"].forEach((methodName) => {
|
|
1316
|
-
Object.defineProperty(obj, methodName + accessorName, {
|
|
1317
|
-
value: function(arg1, arg2, arg3) {
|
|
1318
|
-
return this[methodName].call(this, header, arg1, arg2, arg3);
|
|
1319
|
-
},
|
|
1320
|
-
configurable: true
|
|
1321
|
-
});
|
|
1322
|
-
});
|
|
1323
|
-
}
|
|
1324
|
-
let AxiosHeaders$1 = class AxiosHeaders {
|
|
1325
|
-
constructor(headers) {
|
|
1326
|
-
headers && this.set(headers);
|
|
1327
|
-
}
|
|
1328
|
-
set(header, valueOrRewrite, rewrite) {
|
|
1329
|
-
const self2 = this;
|
|
1330
|
-
function setHeader(_value, _header, _rewrite) {
|
|
1331
|
-
const lHeader = normalizeHeader(_header);
|
|
1332
|
-
if (!lHeader) {
|
|
1333
|
-
throw new Error("header name must be a non-empty string");
|
|
1334
|
-
}
|
|
1335
|
-
const key = utils$1.findKey(self2, lHeader);
|
|
1336
|
-
if (!key || self2[key] === void 0 || _rewrite === true || _rewrite === void 0 && self2[key] !== false) {
|
|
1337
|
-
self2[key || _header] = normalizeValue(_value);
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
const setHeaders = (headers, _rewrite) => utils$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
|
|
1341
|
-
if (utils$1.isPlainObject(header) || header instanceof this.constructor) {
|
|
1342
|
-
setHeaders(header, valueOrRewrite);
|
|
1343
|
-
} else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
|
1344
|
-
setHeaders(parseHeaders(header), valueOrRewrite);
|
|
1345
|
-
} else if (utils$1.isObject(header) && utils$1.isIterable(header)) {
|
|
1346
|
-
let obj = {}, dest, key;
|
|
1347
|
-
for (const entry of header) {
|
|
1348
|
-
if (!utils$1.isArray(entry)) {
|
|
1349
|
-
throw TypeError("Object iterator must return a key-value pair");
|
|
1350
|
-
}
|
|
1351
|
-
obj[key = entry[0]] = (dest = obj[key]) ? utils$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]] : entry[1];
|
|
1352
|
-
}
|
|
1353
|
-
setHeaders(obj, valueOrRewrite);
|
|
1354
|
-
} else {
|
|
1355
|
-
header != null && setHeader(valueOrRewrite, header, rewrite);
|
|
1356
|
-
}
|
|
1357
|
-
return this;
|
|
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
|
+
);
|
|
1358
2162
|
}
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
}
|
|
1368
|
-
if (parser === true) {
|
|
1369
|
-
return parseTokens(value);
|
|
1370
|
-
}
|
|
1371
|
-
if (utils$1.isFunction(parser)) {
|
|
1372
|
-
return parser.call(this, value, key);
|
|
1373
|
-
}
|
|
1374
|
-
if (utils$1.isRegExp(parser)) {
|
|
1375
|
-
return parser.exec(value);
|
|
1376
|
-
}
|
|
1377
|
-
throw new TypeError("parser must be boolean|regexp|function");
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
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]);
|
|
1380
2171
|
}
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
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];
|
|
1388
2183
|
}
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
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;
|
|
1400
2199
|
}
|
|
2200
|
+
return !isNumericKey;
|
|
1401
2201
|
}
|
|
1402
|
-
if (utils$1.
|
|
1403
|
-
|
|
1404
|
-
} else {
|
|
1405
|
-
deleteHeader(header);
|
|
2202
|
+
if (!utils$1.hasOwnProp(target, name2) || !utils$1.isObject(target[name2])) {
|
|
2203
|
+
target[name2] = [];
|
|
1406
2204
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
const keys = Object.keys(this);
|
|
1411
|
-
let i = keys.length;
|
|
1412
|
-
let deleted = false;
|
|
1413
|
-
while (i--) {
|
|
1414
|
-
const key = keys[i];
|
|
1415
|
-
if (!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
|
|
1416
|
-
delete this[key];
|
|
1417
|
-
deleted = true;
|
|
1418
|
-
}
|
|
2205
|
+
const result = buildPath(path, value, target[name2], index2);
|
|
2206
|
+
if (result && utils$1.isArray(target[name2])) {
|
|
2207
|
+
target[name2] = arrayToObject(target[name2]);
|
|
1419
2208
|
}
|
|
1420
|
-
return
|
|
1421
|
-
}
|
|
1422
|
-
normalize(format) {
|
|
1423
|
-
const self2 = this;
|
|
1424
|
-
const headers = {};
|
|
1425
|
-
utils$1.forEach(this, (value, header) => {
|
|
1426
|
-
const key = utils$1.findKey(headers, header);
|
|
1427
|
-
if (key) {
|
|
1428
|
-
self2[key] = normalizeValue(value);
|
|
1429
|
-
delete self2[header];
|
|
1430
|
-
return;
|
|
1431
|
-
}
|
|
1432
|
-
const normalized = format ? formatHeader(header) : String(header).trim();
|
|
1433
|
-
if (normalized !== header) {
|
|
1434
|
-
delete self2[header];
|
|
1435
|
-
}
|
|
1436
|
-
self2[normalized] = normalizeValue(value);
|
|
1437
|
-
headers[normalized] = true;
|
|
1438
|
-
});
|
|
1439
|
-
return this;
|
|
1440
|
-
}
|
|
1441
|
-
concat(...targets) {
|
|
1442
|
-
return this.constructor.concat(this, ...targets);
|
|
2209
|
+
return !isNumericKey;
|
|
1443
2210
|
}
|
|
1444
|
-
|
|
1445
|
-
const obj =
|
|
1446
|
-
utils$1.
|
|
1447
|
-
|
|
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);
|
|
1448
2215
|
});
|
|
1449
2216
|
return obj;
|
|
1450
2217
|
}
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
return thing instanceof this ? thing : new this(thing);
|
|
1465
|
-
}
|
|
1466
|
-
static concat(first, ...targets) {
|
|
1467
|
-
const computed = new this(first);
|
|
1468
|
-
targets.forEach((target) => computed.set(target));
|
|
1469
|
-
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
|
+
}
|
|
1470
2231
|
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
function
|
|
1478
|
-
const
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
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);
|
|
1482
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
|
|
1483
2328
|
}
|
|
1484
|
-
utils$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
|
1485
|
-
return this;
|
|
1486
2329
|
}
|
|
1487
2330
|
};
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
let mapped = key[0].toUpperCase() + key.slice(1);
|
|
1491
|
-
return {
|
|
1492
|
-
get: () => value,
|
|
1493
|
-
set(headerValue) {
|
|
1494
|
-
this[mapped] = headerValue;
|
|
1495
|
-
}
|
|
1496
|
-
};
|
|
2331
|
+
utils$1.forEach(["delete", "get", "head", "post", "put", "patch", "query"], (method) => {
|
|
2332
|
+
defaults.headers[method] = {};
|
|
1497
2333
|
});
|
|
1498
|
-
utils$1.freezeMethods(AxiosHeaders$1);
|
|
1499
2334
|
function transformData(fns, response) {
|
|
1500
2335
|
const config2 = this || defaults;
|
|
1501
2336
|
const context = response || config2;
|
|
@@ -1510,13 +2345,22 @@ function transformData(fns, response) {
|
|
|
1510
2345
|
function isCancel$1(value) {
|
|
1511
2346
|
return !!(value && value.__CANCEL__);
|
|
1512
2347
|
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
}
|
|
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
|
+
};
|
|
1520
2364
|
function settle(resolve, reject, response) {
|
|
1521
2365
|
const validateStatus2 = response.config.validateStatus;
|
|
1522
2366
|
if (!response.status || !validateStatus2 || validateStatus2(response.status)) {
|
|
@@ -1524,7 +2368,7 @@ function settle(resolve, reject, response) {
|
|
|
1524
2368
|
} else {
|
|
1525
2369
|
reject(new AxiosError$1(
|
|
1526
2370
|
"Request failed with status code " + response.status,
|
|
1527
|
-
|
|
2371
|
+
response.status >= 400 && response.status < 500 ? AxiosError$1.ERR_BAD_REQUEST : AxiosError$1.ERR_BAD_RESPONSE,
|
|
1528
2372
|
response.config,
|
|
1529
2373
|
response.request,
|
|
1530
2374
|
response
|
|
@@ -1532,7 +2376,7 @@ function settle(resolve, reject, response) {
|
|
|
1532
2376
|
}
|
|
1533
2377
|
}
|
|
1534
2378
|
function parseProtocol(url) {
|
|
1535
|
-
const match = /^([-+\w]{1,25})(
|
|
2379
|
+
const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url);
|
|
1536
2380
|
return match && match[1] || "";
|
|
1537
2381
|
}
|
|
1538
2382
|
function speedometer(samplesCount, min) {
|
|
@@ -1604,19 +2448,22 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
|
|
1604
2448
|
let bytesNotified = 0;
|
|
1605
2449
|
const _speedometer = speedometer(50, 250);
|
|
1606
2450
|
return throttle((e) => {
|
|
1607
|
-
|
|
2451
|
+
if (!e || typeof e.loaded !== "number") {
|
|
2452
|
+
return;
|
|
2453
|
+
}
|
|
2454
|
+
const rawLoaded = e.loaded;
|
|
1608
2455
|
const total = e.lengthComputable ? e.total : void 0;
|
|
1609
|
-
const
|
|
2456
|
+
const loaded = total != null ? Math.min(rawLoaded, total) : rawLoaded;
|
|
2457
|
+
const progressBytes = Math.max(0, loaded - bytesNotified);
|
|
1610
2458
|
const rate = _speedometer(progressBytes);
|
|
1611
|
-
|
|
1612
|
-
bytesNotified = loaded;
|
|
2459
|
+
bytesNotified = Math.max(bytesNotified, loaded);
|
|
1613
2460
|
const data = {
|
|
1614
2461
|
loaded,
|
|
1615
2462
|
total,
|
|
1616
2463
|
progress: total ? loaded / total : void 0,
|
|
1617
2464
|
bytes: progressBytes,
|
|
1618
2465
|
rate: rate ? rate : void 0,
|
|
1619
|
-
estimated: rate && total
|
|
2466
|
+
estimated: rate && total ? (total - loaded) / rate : void 0,
|
|
1620
2467
|
event: e,
|
|
1621
2468
|
lengthComputable: total != null,
|
|
1622
2469
|
[isDownloadStream ? "download" : "upload"]: true
|
|
@@ -1626,11 +2473,14 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
|
|
1626
2473
|
};
|
|
1627
2474
|
const progressEventDecorator = (total, throttled) => {
|
|
1628
2475
|
const lengthComputable = total != null;
|
|
1629
|
-
return [
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
2476
|
+
return [
|
|
2477
|
+
(loaded) => throttled[0]({
|
|
2478
|
+
lengthComputable,
|
|
2479
|
+
total,
|
|
2480
|
+
loaded
|
|
2481
|
+
}),
|
|
2482
|
+
throttled[1]
|
|
2483
|
+
];
|
|
1634
2484
|
};
|
|
1635
2485
|
const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
|
|
1636
2486
|
const isURLSameOrigin = platform.hasStandardBrowserEnv ? /* @__PURE__ */ ((origin2, isMSIE) => (url) => {
|
|
@@ -1643,20 +2493,44 @@ const isURLSameOrigin = platform.hasStandardBrowserEnv ? /* @__PURE__ */ ((origi
|
|
|
1643
2493
|
const cookies = platform.hasStandardBrowserEnv ? (
|
|
1644
2494
|
// Standard browser envs support document.cookie
|
|
1645
2495
|
{
|
|
1646
|
-
write(
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
utils$1.
|
|
1650
|
-
|
|
1651
|
-
|
|
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
|
+
}
|
|
1652
2514
|
document.cookie = cookie.join("; ");
|
|
1653
2515
|
},
|
|
1654
|
-
read(
|
|
1655
|
-
|
|
1656
|
-
|
|
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;
|
|
1657
2531
|
},
|
|
1658
|
-
remove(
|
|
1659
|
-
this.write(
|
|
2532
|
+
remove(name2) {
|
|
2533
|
+
this.write(name2, "", Date.now() - 864e5, "/");
|
|
1660
2534
|
}
|
|
1661
2535
|
}
|
|
1662
2536
|
) : (
|
|
@@ -1672,22 +2546,58 @@ const cookies = platform.hasStandardBrowserEnv ? (
|
|
|
1672
2546
|
}
|
|
1673
2547
|
);
|
|
1674
2548
|
function isAbsoluteURL(url) {
|
|
2549
|
+
if (typeof url !== "string") {
|
|
2550
|
+
return false;
|
|
2551
|
+
}
|
|
1675
2552
|
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
|
1676
2553
|
}
|
|
1677
2554
|
function combineURLs(baseURL, relativeURL) {
|
|
1678
2555
|
return relativeURL ? baseURL.replace(/\/?\/$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
|
|
1679
2556
|
}
|
|
1680
|
-
|
|
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);
|
|
1681
2580
|
let isRelativeUrl = !isAbsoluteURL(requestedURL);
|
|
1682
|
-
if (baseURL && (isRelativeUrl || allowAbsoluteUrls
|
|
2581
|
+
if (baseURL && (isRelativeUrl || allowAbsoluteUrls === false)) {
|
|
2582
|
+
assertValidHttpProtocolURL(baseURL, config2);
|
|
1683
2583
|
return combineURLs(baseURL, requestedURL);
|
|
1684
2584
|
}
|
|
1685
2585
|
return requestedURL;
|
|
1686
2586
|
}
|
|
1687
2587
|
const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? { ...thing } : thing;
|
|
1688
2588
|
function mergeConfig$1(config1, config2) {
|
|
2589
|
+
config1 = config1 || {};
|
|
1689
2590
|
config2 = config2 || {};
|
|
1690
|
-
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
|
+
});
|
|
1691
2601
|
function getMergedValue(target, source, prop, caseless) {
|
|
1692
2602
|
if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
|
|
1693
2603
|
return utils$1.merge.call({ caseless }, target, source);
|
|
@@ -1717,10 +2627,27 @@ function mergeConfig$1(config1, config2) {
|
|
|
1717
2627
|
return getMergedValue(void 0, a);
|
|
1718
2628
|
}
|
|
1719
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
|
+
}
|
|
1720
2647
|
function mergeDirectKeys(a, b, prop) {
|
|
1721
|
-
if (prop
|
|
2648
|
+
if (utils$1.hasOwnProp(config2, prop)) {
|
|
1722
2649
|
return getMergedValue(a, b);
|
|
1723
|
-
} else if (prop
|
|
2650
|
+
} else if (utils$1.hasOwnProp(config1, prop)) {
|
|
1724
2651
|
return getMergedValue(void 0, a);
|
|
1725
2652
|
}
|
|
1726
2653
|
}
|
|
@@ -1751,44 +2678,87 @@ function mergeConfig$1(config1, config2) {
|
|
|
1751
2678
|
httpsAgent: defaultToConfig2,
|
|
1752
2679
|
cancelToken: defaultToConfig2,
|
|
1753
2680
|
socketPath: defaultToConfig2,
|
|
2681
|
+
allowedSocketPaths: defaultToConfig2,
|
|
1754
2682
|
responseEncoding: defaultToConfig2,
|
|
1755
2683
|
validateStatus: mergeDirectKeys,
|
|
1756
2684
|
headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
|
|
1757
2685
|
};
|
|
1758
2686
|
utils$1.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
|
|
1759
|
-
|
|
1760
|
-
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);
|
|
1761
2692
|
utils$1.isUndefined(configValue) && merge2 !== mergeDirectKeys || (config3[prop] = configValue);
|
|
1762
2693
|
});
|
|
1763
|
-
|
|
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
|
+
}
|
|
2701
|
+
return config3;
|
|
2702
|
+
}
|
|
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
|
+
});
|
|
1764
2714
|
}
|
|
1765
|
-
const
|
|
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) {
|
|
1766
2720
|
const newConfig = mergeConfig$1({}, config2);
|
|
1767
|
-
|
|
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");
|
|
1768
2731
|
newConfig.headers = headers = AxiosHeaders$1.from(headers);
|
|
1769
|
-
newConfig.url = buildURL(
|
|
2732
|
+
newConfig.url = buildURL(
|
|
2733
|
+
buildFullPath(baseURL, url, allowAbsoluteUrls, newConfig),
|
|
2734
|
+
own2("params"),
|
|
2735
|
+
own2("paramsSerializer")
|
|
2736
|
+
);
|
|
1770
2737
|
if (auth) {
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
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
|
+
}
|
|
1775
2748
|
}
|
|
1776
2749
|
if (utils$1.isFormData(data)) {
|
|
1777
|
-
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
|
2750
|
+
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv || utils$1.isReactNative(data)) {
|
|
1778
2751
|
headers.setContentType(void 0);
|
|
1779
2752
|
} else if (utils$1.isFunction(data.getHeaders)) {
|
|
1780
|
-
|
|
1781
|
-
const allowedHeaders = ["content-type", "content-length"];
|
|
1782
|
-
Object.entries(formHeaders).forEach(([key, val]) => {
|
|
1783
|
-
if (allowedHeaders.includes(key.toLowerCase())) {
|
|
1784
|
-
headers.set(key, val);
|
|
1785
|
-
}
|
|
1786
|
-
});
|
|
2753
|
+
setFormDataHeaders(headers, data.getHeaders(), own2("formDataHeaderPolicy"));
|
|
1787
2754
|
}
|
|
1788
2755
|
}
|
|
1789
2756
|
if (platform.hasStandardBrowserEnv) {
|
|
1790
|
-
|
|
1791
|
-
|
|
2757
|
+
if (utils$1.isFunction(withXSRFToken)) {
|
|
2758
|
+
withXSRFToken = withXSRFToken(newConfig);
|
|
2759
|
+
}
|
|
2760
|
+
const shouldSendXSRF = withXSRFToken === true || withXSRFToken == null && isURLSameOrigin(newConfig.url);
|
|
2761
|
+
if (shouldSendXSRF) {
|
|
1792
2762
|
const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
|
|
1793
2763
|
if (xsrfValue) {
|
|
1794
2764
|
headers.set(xsrfHeaderName, xsrfValue);
|
|
@@ -1796,7 +2766,7 @@ const resolveConfig = (config2) => {
|
|
|
1796
2766
|
}
|
|
1797
2767
|
}
|
|
1798
2768
|
return newConfig;
|
|
1799
|
-
}
|
|
2769
|
+
}
|
|
1800
2770
|
const isXHRAdapterSupported = typeof XMLHttpRequest !== "undefined";
|
|
1801
2771
|
const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
1802
2772
|
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
@@ -1832,13 +2802,17 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1832
2802
|
config: config2,
|
|
1833
2803
|
request
|
|
1834
2804
|
};
|
|
1835
|
-
settle(
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
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
|
+
);
|
|
1842
2816
|
request = null;
|
|
1843
2817
|
}
|
|
1844
2818
|
if ("onloadend" in request) {
|
|
@@ -1848,7 +2822,7 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1848
2822
|
if (!request || request.readyState !== 4) {
|
|
1849
2823
|
return;
|
|
1850
2824
|
}
|
|
1851
|
-
if (request.status === 0 && !(request.responseURL && request.responseURL.
|
|
2825
|
+
if (request.status === 0 && !(request.responseURL && request.responseURL.startsWith("file:"))) {
|
|
1852
2826
|
return;
|
|
1853
2827
|
}
|
|
1854
2828
|
setTimeout(onloadend);
|
|
@@ -1859,6 +2833,7 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1859
2833
|
return;
|
|
1860
2834
|
}
|
|
1861
2835
|
reject(new AxiosError$1("Request aborted", AxiosError$1.ECONNABORTED, config2, request));
|
|
2836
|
+
done();
|
|
1862
2837
|
request = null;
|
|
1863
2838
|
};
|
|
1864
2839
|
request.onerror = function handleError(event) {
|
|
@@ -1866,6 +2841,7 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1866
2841
|
const err = new AxiosError$1(msg, AxiosError$1.ERR_NETWORK, config2, request);
|
|
1867
2842
|
err.event = event || null;
|
|
1868
2843
|
reject(err);
|
|
2844
|
+
done();
|
|
1869
2845
|
request = null;
|
|
1870
2846
|
};
|
|
1871
2847
|
request.ontimeout = function handleTimeout() {
|
|
@@ -1874,17 +2850,20 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1874
2850
|
if (_config.timeoutErrorMessage) {
|
|
1875
2851
|
timeoutErrorMessage = _config.timeoutErrorMessage;
|
|
1876
2852
|
}
|
|
1877
|
-
reject(
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
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();
|
|
1883
2862
|
request = null;
|
|
1884
2863
|
};
|
|
1885
2864
|
requestData === void 0 && requestHeaders.setContentType(null);
|
|
1886
2865
|
if ("setRequestHeader" in request) {
|
|
1887
|
-
utils$1.forEach(requestHeaders
|
|
2866
|
+
utils$1.forEach(toByteStringHeaderObject(requestHeaders), function setRequestHeader(val, key) {
|
|
1888
2867
|
request.setRequestHeader(key, val);
|
|
1889
2868
|
});
|
|
1890
2869
|
}
|
|
@@ -1910,6 +2889,7 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1910
2889
|
}
|
|
1911
2890
|
reject(!cancel || cancel.type ? new CanceledError$1(null, config2, request) : cancel);
|
|
1912
2891
|
request.abort();
|
|
2892
|
+
done();
|
|
1913
2893
|
request = null;
|
|
1914
2894
|
};
|
|
1915
2895
|
_config.cancelToken && _config.cancelToken.subscribe(onCanceled);
|
|
@@ -1918,45 +2898,56 @@ const xhrAdapter = isXHRAdapterSupported && function(config2) {
|
|
|
1918
2898
|
}
|
|
1919
2899
|
}
|
|
1920
2900
|
const protocol = parseProtocol(_config.url);
|
|
1921
|
-
if (protocol && platform.protocols.
|
|
1922
|
-
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();
|
|
1923
2910
|
return;
|
|
1924
2911
|
}
|
|
1925
2912
|
request.send(requestData || null);
|
|
1926
2913
|
});
|
|
1927
2914
|
};
|
|
1928
2915
|
const composeSignals = (signals, timeout) => {
|
|
1929
|
-
|
|
1930
|
-
if (timeout
|
|
1931
|
-
|
|
1932
|
-
let aborted;
|
|
1933
|
-
const onabort = function(reason) {
|
|
1934
|
-
if (!aborted) {
|
|
1935
|
-
aborted = true;
|
|
1936
|
-
unsubscribe();
|
|
1937
|
-
const err = reason instanceof Error ? reason : this.reason;
|
|
1938
|
-
controller2.abort(err instanceof AxiosError$1 ? err : new CanceledError$1(err instanceof Error ? err.message : err));
|
|
1939
|
-
}
|
|
1940
|
-
};
|
|
1941
|
-
let timer = timeout && setTimeout(() => {
|
|
1942
|
-
timer = null;
|
|
1943
|
-
onabort(new AxiosError$1(`timeout ${timeout} of ms exceeded`, AxiosError$1.ETIMEDOUT));
|
|
1944
|
-
}, timeout);
|
|
1945
|
-
const unsubscribe = () => {
|
|
1946
|
-
if (signals) {
|
|
1947
|
-
timer && clearTimeout(timer);
|
|
1948
|
-
timer = null;
|
|
1949
|
-
signals.forEach((signal2) => {
|
|
1950
|
-
signal2.unsubscribe ? signal2.unsubscribe(onabort) : signal2.removeEventListener("abort", onabort);
|
|
1951
|
-
});
|
|
1952
|
-
signals = null;
|
|
1953
|
-
}
|
|
1954
|
-
};
|
|
1955
|
-
signals.forEach((signal2) => signal2.addEventListener("abort", onabort));
|
|
1956
|
-
const { signal } = controller2;
|
|
1957
|
-
signal.unsubscribe = () => utils$1.asap(unsubscribe);
|
|
1958
|
-
return signal;
|
|
2916
|
+
signals = signals ? signals.filter(Boolean) : [];
|
|
2917
|
+
if (!timeout && !signals.length) {
|
|
2918
|
+
return;
|
|
1959
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;
|
|
1960
2951
|
};
|
|
1961
2952
|
const streamChunk = function* (chunk, chunkSize) {
|
|
1962
2953
|
let len = chunk.byteLength;
|
|
@@ -2005,44 +2996,127 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
|
|
2005
2996
|
onFinish && onFinish(e);
|
|
2006
2997
|
}
|
|
2007
2998
|
};
|
|
2008
|
-
return new ReadableStream(
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
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;
|
|
2021
3018
|
}
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
_onFinish(
|
|
2025
|
-
|
|
3019
|
+
},
|
|
3020
|
+
cancel(reason) {
|
|
3021
|
+
_onFinish(reason);
|
|
3022
|
+
return iterator2.return();
|
|
2026
3023
|
}
|
|
2027
3024
|
},
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
return iterator2.return();
|
|
3025
|
+
{
|
|
3026
|
+
highWaterMark: 2
|
|
2031
3027
|
}
|
|
2032
|
-
|
|
2033
|
-
highWaterMark: 2
|
|
2034
|
-
});
|
|
3028
|
+
);
|
|
2035
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";
|
|
2036
3104
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
2037
3105
|
const { isFunction } = utils$1;
|
|
2038
|
-
const
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
const {
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
}
|
|
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
|
+
};
|
|
2046
3120
|
const test = (fn, ...args) => {
|
|
2047
3121
|
try {
|
|
2048
3122
|
return !!fn(...args);
|
|
@@ -2050,10 +3124,27 @@ const test = (fn, ...args) => {
|
|
|
2050
3124
|
return false;
|
|
2051
3125
|
}
|
|
2052
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
|
+
};
|
|
2053
3135
|
const factory = (env) => {
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
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
|
+
);
|
|
2057
3148
|
const { fetch: envFetch, Request, Response } = env;
|
|
2058
3149
|
const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === "function";
|
|
2059
3150
|
const isRequestSupported = isFunction(Request);
|
|
@@ -2061,18 +3152,22 @@ const factory = (env) => {
|
|
|
2061
3152
|
if (!isFetchSupported) {
|
|
2062
3153
|
return false;
|
|
2063
3154
|
}
|
|
2064
|
-
const isReadableStreamSupported = isFetchSupported && isFunction(
|
|
2065
|
-
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()));
|
|
2066
3157
|
const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
|
2067
3158
|
let duplexAccessed = false;
|
|
2068
|
-
const
|
|
2069
|
-
body: new
|
|
3159
|
+
const request = new Request(platform.origin, {
|
|
3160
|
+
body: new ReadableStream2(),
|
|
2070
3161
|
method: "POST",
|
|
2071
3162
|
get duplex() {
|
|
2072
3163
|
duplexAccessed = true;
|
|
2073
3164
|
return "half";
|
|
2074
3165
|
}
|
|
2075
|
-
})
|
|
3166
|
+
});
|
|
3167
|
+
const hasContentType = request.headers.has("Content-Type");
|
|
3168
|
+
if (request.body != null) {
|
|
3169
|
+
request.body.cancel();
|
|
3170
|
+
}
|
|
2076
3171
|
return duplexAccessed && !hasContentType;
|
|
2077
3172
|
});
|
|
2078
3173
|
const supportsResponseStream = isResponseSupported && isReadableStreamSupported && test(() => utils$1.isReadableStream(new Response("").body));
|
|
@@ -2086,7 +3181,11 @@ const factory = (env) => {
|
|
|
2086
3181
|
if (method) {
|
|
2087
3182
|
return method.call(res);
|
|
2088
3183
|
}
|
|
2089
|
-
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
|
+
);
|
|
2090
3189
|
});
|
|
2091
3190
|
});
|
|
2092
3191
|
})();
|
|
@@ -2131,63 +3230,189 @@ const factory = (env) => {
|
|
|
2131
3230
|
responseType,
|
|
2132
3231
|
headers,
|
|
2133
3232
|
withCredentials = "same-origin",
|
|
2134
|
-
fetchOptions
|
|
3233
|
+
fetchOptions,
|
|
3234
|
+
maxContentLength,
|
|
3235
|
+
maxBodyLength
|
|
2135
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;
|
|
2136
3240
|
let _fetch = envFetch || fetch;
|
|
2137
3241
|
responseType = responseType ? (responseType + "").toLowerCase() : "text";
|
|
2138
|
-
let composedSignal = composeSignals(
|
|
3242
|
+
let composedSignal = composeSignals(
|
|
3243
|
+
[signal, cancelToken && cancelToken.toAbortSignal()],
|
|
3244
|
+
timeout
|
|
3245
|
+
);
|
|
2139
3246
|
let request = null;
|
|
2140
3247
|
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
2141
3248
|
composedSignal.unsubscribe();
|
|
2142
3249
|
});
|
|
2143
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
|
+
);
|
|
2144
3258
|
try {
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
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;
|
|
2154
3283
|
}
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
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
|
|
2159
3300
|
);
|
|
2160
|
-
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
|
2161
3301
|
}
|
|
2162
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
|
+
}
|
|
2163
3354
|
if (!utils$1.isString(withCredentials)) {
|
|
2164
3355
|
withCredentials = withCredentials ? "include" : "omit";
|
|
2165
3356
|
}
|
|
2166
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);
|
|
2167
3365
|
const resolvedOptions = {
|
|
2168
3366
|
...fetchOptions,
|
|
2169
3367
|
signal: composedSignal,
|
|
2170
3368
|
method: method.toUpperCase(),
|
|
2171
|
-
headers: headers.normalize()
|
|
3369
|
+
headers: toByteStringHeaderObject(headers.normalize()),
|
|
2172
3370
|
body: data,
|
|
2173
3371
|
duplex: "half",
|
|
2174
3372
|
credentials: isCredentialsSupported ? withCredentials : void 0
|
|
2175
3373
|
};
|
|
2176
3374
|
request = isRequestSupported && new Request(url, resolvedOptions);
|
|
2177
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
|
+
}
|
|
2178
3388
|
const isStreamResponse = supportsResponseStream && (responseType === "stream" || responseType === "response");
|
|
2179
|
-
if (supportsResponseStream && (onDownloadProgress || isStreamResponse && unsubscribe)) {
|
|
3389
|
+
if (supportsResponseStream && response.body && (onDownloadProgress || hasMaxContentLength || isStreamResponse && unsubscribe)) {
|
|
2180
3390
|
const options = {};
|
|
2181
3391
|
["status", "statusText", "headers"].forEach((prop) => {
|
|
2182
3392
|
options[prop] = response[prop];
|
|
2183
3393
|
});
|
|
2184
|
-
const responseContentLength = utils$1.toFiniteNumber(
|
|
3394
|
+
const responseContentLength = utils$1.toFiniteNumber(responseHeaders.getContentLength());
|
|
2185
3395
|
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
|
2186
3396
|
responseContentLength,
|
|
2187
3397
|
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
|
2188
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
|
+
};
|
|
2189
3414
|
response = new Response(
|
|
2190
|
-
trackStream(response.body, DEFAULT_CHUNK_SIZE,
|
|
3415
|
+
trackStream(response.body, DEFAULT_CHUNK_SIZE, onChunkProgress, () => {
|
|
2191
3416
|
flush && flush();
|
|
2192
3417
|
unsubscribe && unsubscribe();
|
|
2193
3418
|
}),
|
|
@@ -2195,7 +3420,30 @@ const factory = (env) => {
|
|
|
2195
3420
|
);
|
|
2196
3421
|
}
|
|
2197
3422
|
responseType = responseType || "text";
|
|
2198
|
-
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
|
+
}
|
|
2199
3447
|
!isStreamResponse && unsubscribe && unsubscribe();
|
|
2200
3448
|
return await new Promise((resolve, reject) => {
|
|
2201
3449
|
settle(resolve, reject, {
|
|
@@ -2209,27 +3457,55 @@ const factory = (env) => {
|
|
|
2209
3457
|
});
|
|
2210
3458
|
} catch (err) {
|
|
2211
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
|
+
}
|
|
2212
3483
|
if (err && err.name === "TypeError" && /Load failed|fetch/i.test(err.message)) {
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
3484
|
+
const networkError = new AxiosError$1(
|
|
3485
|
+
"Network Error",
|
|
3486
|
+
AxiosError$1.ERR_NETWORK,
|
|
3487
|
+
config2,
|
|
3488
|
+
request,
|
|
3489
|
+
err && err.response
|
|
2218
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;
|
|
2219
3499
|
}
|
|
2220
|
-
throw AxiosError$1.from(err, err && err.code, config2, request);
|
|
3500
|
+
throw AxiosError$1.from(err, err && err.code, config2, request, err && err.response);
|
|
2221
3501
|
}
|
|
2222
3502
|
};
|
|
2223
3503
|
};
|
|
2224
3504
|
const seedCache = /* @__PURE__ */ new Map();
|
|
2225
3505
|
const getFetch = (config2) => {
|
|
2226
|
-
let env = config2
|
|
3506
|
+
let env = config2 && config2.env || {};
|
|
2227
3507
|
const { fetch: fetch2, Request, Response } = env;
|
|
2228
|
-
const seeds = [
|
|
2229
|
-
Request,
|
|
2230
|
-
Response,
|
|
2231
|
-
fetch2
|
|
2232
|
-
];
|
|
3508
|
+
const seeds = [Request, Response, fetch2];
|
|
2233
3509
|
let len = seeds.length, i = len, seed, target, map = seedCache;
|
|
2234
3510
|
while (i--) {
|
|
2235
3511
|
seed = seeds[i];
|
|
@@ -2250,48 +3526,57 @@ const knownAdapters = {
|
|
|
2250
3526
|
utils$1.forEach(knownAdapters, (fn, value) => {
|
|
2251
3527
|
if (fn) {
|
|
2252
3528
|
try {
|
|
2253
|
-
Object.defineProperty(fn, "name", { value });
|
|
3529
|
+
Object.defineProperty(fn, "name", { __proto__: null, value });
|
|
2254
3530
|
} catch (e) {
|
|
2255
3531
|
}
|
|
2256
|
-
Object.defineProperty(fn, "adapterName", { value });
|
|
3532
|
+
Object.defineProperty(fn, "adapterName", { __proto__: null, value });
|
|
2257
3533
|
}
|
|
2258
3534
|
});
|
|
2259
3535
|
const renderReason = (reason) => `- ${reason}`;
|
|
2260
3536
|
const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
throw new AxiosError$1(`Unknown adapter '${id}'`);
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
2278
|
-
if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config2)))) {
|
|
2279
|
-
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}'`);
|
|
2280
3551
|
}
|
|
2281
|
-
rejectedReasons[id || "#" + i] = adapter;
|
|
2282
3552
|
}
|
|
2283
|
-
if (
|
|
2284
|
-
|
|
2285
|
-
([id, state]) => `adapter ${id} ` + (state === false ? "is not supported by the environment" : "is not available in the build")
|
|
2286
|
-
);
|
|
2287
|
-
let s = length ? reasons.length > 1 ? "since :\n" + reasons.map(renderReason).join("\n") : " " + renderReason(reasons[0]) : "as no adapter specified";
|
|
2288
|
-
throw new AxiosError$1(
|
|
2289
|
-
`There is no suitable adapter to dispatch the request ` + s,
|
|
2290
|
-
"ERR_NOT_SUPPORT"
|
|
2291
|
-
);
|
|
3553
|
+
if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config2)))) {
|
|
3554
|
+
break;
|
|
2292
3555
|
}
|
|
2293
|
-
|
|
2294
|
-
}
|
|
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
|
+
*/
|
|
2295
3580
|
adapters: knownAdapters
|
|
2296
3581
|
};
|
|
2297
3582
|
function throwIfCancellationRequested(config2) {
|
|
@@ -2305,39 +3590,44 @@ function throwIfCancellationRequested(config2) {
|
|
|
2305
3590
|
function dispatchRequest(config2) {
|
|
2306
3591
|
throwIfCancellationRequested(config2);
|
|
2307
3592
|
config2.headers = AxiosHeaders$1.from(config2.headers);
|
|
2308
|
-
config2.data = transformData.call(
|
|
2309
|
-
config2,
|
|
2310
|
-
config2.transformRequest
|
|
2311
|
-
);
|
|
3593
|
+
config2.data = transformData.call(config2, config2.transformRequest);
|
|
2312
3594
|
if (["post", "put", "patch"].indexOf(config2.method) !== -1) {
|
|
2313
3595
|
config2.headers.setContentType("application/x-www-form-urlencoded", false);
|
|
2314
3596
|
}
|
|
2315
3597
|
const adapter = adapters.getAdapter(config2.adapter || defaults.adapter, config2);
|
|
2316
|
-
return adapter(config2).then(
|
|
2317
|
-
|
|
2318
|
-
response.data = transformData.call(
|
|
2319
|
-
config2,
|
|
2320
|
-
config2.transformResponse,
|
|
2321
|
-
response
|
|
2322
|
-
);
|
|
2323
|
-
response.headers = AxiosHeaders$1.from(response.headers);
|
|
2324
|
-
return response;
|
|
2325
|
-
}, function onAdapterRejection(reason) {
|
|
2326
|
-
if (!isCancel$1(reason)) {
|
|
3598
|
+
return adapter(config2).then(
|
|
3599
|
+
function onAdapterResolution(response) {
|
|
2327
3600
|
throwIfCancellationRequested(config2);
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
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
|
+
}
|
|
2335
3626
|
}
|
|
3627
|
+
return Promise.reject(reason);
|
|
2336
3628
|
}
|
|
2337
|
-
|
|
2338
|
-
});
|
|
3629
|
+
);
|
|
2339
3630
|
}
|
|
2340
|
-
const VERSION$1 = "1.12.2";
|
|
2341
3631
|
const validators$1 = {};
|
|
2342
3632
|
["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i) => {
|
|
2343
3633
|
validators$1[type] = function validator2(thing) {
|
|
@@ -2374,20 +3664,23 @@ validators$1.spelling = function spelling(correctSpelling) {
|
|
|
2374
3664
|
return true;
|
|
2375
3665
|
};
|
|
2376
3666
|
};
|
|
2377
|
-
function assertOptions(options,
|
|
2378
|
-
if (typeof options !== "object") {
|
|
3667
|
+
function assertOptions(options, schema2, allowUnknown) {
|
|
3668
|
+
if (typeof options !== "object" || options === null) {
|
|
2379
3669
|
throw new AxiosError$1("options must be an object", AxiosError$1.ERR_BAD_OPTION_VALUE);
|
|
2380
3670
|
}
|
|
2381
3671
|
const keys = Object.keys(options);
|
|
2382
3672
|
let i = keys.length;
|
|
2383
3673
|
while (i-- > 0) {
|
|
2384
3674
|
const opt = keys[i];
|
|
2385
|
-
const validator2 =
|
|
3675
|
+
const validator2 = Object.prototype.hasOwnProperty.call(schema2, opt) ? schema2[opt] : void 0;
|
|
2386
3676
|
if (validator2) {
|
|
2387
3677
|
const value = options[opt];
|
|
2388
3678
|
const result = value === void 0 || validator2(value, opt, options);
|
|
2389
3679
|
if (result !== true) {
|
|
2390
|
-
throw new AxiosError$1(
|
|
3680
|
+
throw new AxiosError$1(
|
|
3681
|
+
"option " + opt + " must be " + result,
|
|
3682
|
+
AxiosError$1.ERR_BAD_OPTION_VALUE
|
|
3683
|
+
);
|
|
2391
3684
|
}
|
|
2392
3685
|
continue;
|
|
2393
3686
|
}
|
|
@@ -2424,12 +3717,23 @@ let Axios$1 = class Axios {
|
|
|
2424
3717
|
if (err instanceof Error) {
|
|
2425
3718
|
let dummy = {};
|
|
2426
3719
|
Error.captureStackTrace ? Error.captureStackTrace(dummy) : dummy = new Error();
|
|
2427
|
-
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
|
+
})();
|
|
2428
3727
|
try {
|
|
2429
3728
|
if (!err.stack) {
|
|
2430
3729
|
err.stack = stack;
|
|
2431
|
-
} else if (stack
|
|
2432
|
-
|
|
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
|
+
}
|
|
2433
3737
|
}
|
|
2434
3738
|
} catch (e) {
|
|
2435
3739
|
}
|
|
@@ -2447,11 +3751,18 @@ let Axios$1 = class Axios {
|
|
|
2447
3751
|
config2 = mergeConfig$1(this.defaults, config2);
|
|
2448
3752
|
const { transitional: transitional2, paramsSerializer, headers } = config2;
|
|
2449
3753
|
if (transitional2 !== void 0) {
|
|
2450
|
-
validator.assertOptions(
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
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
|
+
);
|
|
2455
3766
|
}
|
|
2456
3767
|
if (paramsSerializer != null) {
|
|
2457
3768
|
if (utils$1.isFunction(paramsSerializer)) {
|
|
@@ -2459,10 +3770,14 @@ let Axios$1 = class Axios {
|
|
|
2459
3770
|
serialize: paramsSerializer
|
|
2460
3771
|
};
|
|
2461
3772
|
} else {
|
|
2462
|
-
validator.assertOptions(
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
3773
|
+
validator.assertOptions(
|
|
3774
|
+
paramsSerializer,
|
|
3775
|
+
{
|
|
3776
|
+
encode: validators.function,
|
|
3777
|
+
serialize: validators.function
|
|
3778
|
+
},
|
|
3779
|
+
true
|
|
3780
|
+
);
|
|
2466
3781
|
}
|
|
2467
3782
|
}
|
|
2468
3783
|
if (config2.allowAbsoluteUrls !== void 0) ;
|
|
@@ -2471,21 +3786,19 @@ let Axios$1 = class Axios {
|
|
|
2471
3786
|
} else {
|
|
2472
3787
|
config2.allowAbsoluteUrls = true;
|
|
2473
3788
|
}
|
|
2474
|
-
validator.assertOptions(
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
headers[config2.method]
|
|
2482
|
-
);
|
|
2483
|
-
headers && utils$1.forEach(
|
|
2484
|
-
["delete", "get", "head", "post", "put", "patch", "common"],
|
|
2485
|
-
(method) => {
|
|
2486
|
-
delete headers[method];
|
|
2487
|
-
}
|
|
3789
|
+
validator.assertOptions(
|
|
3790
|
+
config2,
|
|
3791
|
+
{
|
|
3792
|
+
baseUrl: validators.spelling("baseURL"),
|
|
3793
|
+
withXsrfToken: validators.spelling("withXSRFToken")
|
|
3794
|
+
},
|
|
3795
|
+
true
|
|
2488
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
|
+
});
|
|
2489
3802
|
config2.headers = AxiosHeaders$1.concat(contextHeaders, headers);
|
|
2490
3803
|
const requestInterceptorChain = [];
|
|
2491
3804
|
let synchronousRequestInterceptors = true;
|
|
@@ -2494,7 +3807,13 @@ let Axios$1 = class Axios {
|
|
|
2494
3807
|
return;
|
|
2495
3808
|
}
|
|
2496
3809
|
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
|
2497
|
-
|
|
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
|
+
}
|
|
2498
3817
|
});
|
|
2499
3818
|
const responseInterceptorChain = [];
|
|
2500
3819
|
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
|
@@ -2540,34 +3859,40 @@ let Axios$1 = class Axios {
|
|
|
2540
3859
|
}
|
|
2541
3860
|
getUri(config2) {
|
|
2542
3861
|
config2 = mergeConfig$1(this.defaults, config2);
|
|
2543
|
-
const fullPath = buildFullPath(config2.baseURL, config2.url, config2.allowAbsoluteUrls);
|
|
3862
|
+
const fullPath = buildFullPath(config2.baseURL, config2.url, config2.allowAbsoluteUrls, config2);
|
|
2544
3863
|
return buildURL(fullPath, config2.params, config2.paramsSerializer);
|
|
2545
3864
|
}
|
|
2546
3865
|
};
|
|
2547
3866
|
utils$1.forEach(["delete", "get", "head", "options"], function forEachMethodNoData(method) {
|
|
2548
3867
|
Axios$1.prototype[method] = function(url, config2) {
|
|
2549
|
-
return this.request(
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
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
|
+
);
|
|
2554
3875
|
};
|
|
2555
3876
|
});
|
|
2556
|
-
utils$1.forEach(["post", "put", "patch"], function forEachMethodWithData(method) {
|
|
3877
|
+
utils$1.forEach(["post", "put", "patch", "query"], function forEachMethodWithData(method) {
|
|
2557
3878
|
function generateHTTPMethod(isForm) {
|
|
2558
3879
|
return function httpMethod(url, data, config2) {
|
|
2559
|
-
return this.request(
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
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
|
+
);
|
|
2567
3890
|
};
|
|
2568
3891
|
}
|
|
2569
3892
|
Axios$1.prototype[method] = generateHTTPMethod();
|
|
2570
|
-
|
|
3893
|
+
if (method !== "query") {
|
|
3894
|
+
Axios$1.prototype[method + "Form"] = generateHTTPMethod(true);
|
|
3895
|
+
}
|
|
2571
3896
|
});
|
|
2572
3897
|
let CancelToken$1 = class CancelToken {
|
|
2573
3898
|
constructor(executor) {
|
|
@@ -2735,7 +4060,13 @@ const HttpStatusCode$1 = {
|
|
|
2735
4060
|
InsufficientStorage: 507,
|
|
2736
4061
|
LoopDetected: 508,
|
|
2737
4062
|
NotExtended: 510,
|
|
2738
|
-
NetworkAuthenticationRequired: 511
|
|
4063
|
+
NetworkAuthenticationRequired: 511,
|
|
4064
|
+
WebServerIsDown: 521,
|
|
4065
|
+
ConnectionTimedOut: 522,
|
|
4066
|
+
OriginIsUnreachable: 523,
|
|
4067
|
+
TimeoutOccurred: 524,
|
|
4068
|
+
SslHandshakeFailed: 525,
|
|
4069
|
+
InvalidSslCertificate: 526
|
|
2739
4070
|
};
|
|
2740
4071
|
Object.entries(HttpStatusCode$1).forEach(([key, value]) => {
|
|
2741
4072
|
HttpStatusCode$1[value] = key;
|
|
@@ -2745,7 +4076,7 @@ function createInstance(defaultConfig) {
|
|
|
2745
4076
|
const instance = bind(Axios$1.prototype.request, context);
|
|
2746
4077
|
utils$1.extend(instance, Axios$1.prototype, context, { allOwnKeys: true });
|
|
2747
4078
|
utils$1.extend(instance, context, null, { allOwnKeys: true });
|
|
2748
|
-
instance.create = function
|
|
4079
|
+
instance.create = function create2(instanceConfig) {
|
|
2749
4080
|
return createInstance(mergeConfig$1(defaultConfig, instanceConfig));
|
|
2750
4081
|
};
|
|
2751
4082
|
return instance;
|
|
@@ -2772,8 +4103,8 @@ axios.HttpStatusCode = HttpStatusCode$1;
|
|
|
2772
4103
|
axios.default = axios;
|
|
2773
4104
|
const {
|
|
2774
4105
|
Axios: Axios2,
|
|
2775
|
-
AxiosError,
|
|
2776
|
-
CanceledError,
|
|
4106
|
+
AxiosError: AxiosError2,
|
|
4107
|
+
CanceledError: CanceledError2,
|
|
2777
4108
|
isCancel,
|
|
2778
4109
|
CancelToken: CancelToken2,
|
|
2779
4110
|
VERSION,
|
|
@@ -2786,7 +4117,8 @@ const {
|
|
|
2786
4117
|
HttpStatusCode,
|
|
2787
4118
|
formToJSON,
|
|
2788
4119
|
getAdapter,
|
|
2789
|
-
mergeConfig
|
|
4120
|
+
mergeConfig,
|
|
4121
|
+
create
|
|
2790
4122
|
} = axios;
|
|
2791
4123
|
const service = ({ strapi }) => {
|
|
2792
4124
|
return {
|
|
@@ -2817,54 +4149,44 @@ const service = ({ strapi }) => {
|
|
|
2817
4149
|
async getUsuarios(sanitizedQueryParams) {
|
|
2818
4150
|
return await strapi.documents("plugin::users-permissions.user").findMany(sanitizedQueryParams);
|
|
2819
4151
|
},
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
4152
|
+
// ───────────────────────────────
|
|
4153
|
+
// 📥 Proxy File Download (bypasses browser CORS)
|
|
4154
|
+
// ───────────────────────────────
|
|
4155
|
+
async downloadFile(ctx) {
|
|
4156
|
+
const { url } = ctx.request.body;
|
|
4157
|
+
if (!url) {
|
|
4158
|
+
ctx.status = 400;
|
|
4159
|
+
ctx.body = { error: "Se requiere el parámetro 'url'." };
|
|
4160
|
+
return;
|
|
4161
|
+
}
|
|
4162
|
+
let parsedUrl;
|
|
4163
|
+
try {
|
|
4164
|
+
parsedUrl = new URL(url);
|
|
4165
|
+
const allowedHosts = [
|
|
4166
|
+
"web-cms-interware.s3.us-east-1.amazonaws.com",
|
|
4167
|
+
"api.interware.com.mx",
|
|
4168
|
+
...process.env.NODE_ENV === "development" ? ["localhost"] : []
|
|
4169
|
+
];
|
|
4170
|
+
if (!allowedHosts.includes(parsedUrl.hostname)) {
|
|
4171
|
+
ctx.status = 403;
|
|
4172
|
+
ctx.body = { error: "URL no permitida." };
|
|
4173
|
+
return;
|
|
2824
4174
|
}
|
|
2825
|
-
}
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
folder: {
|
|
2830
|
-
id: {
|
|
2831
|
-
$eq: existingFolders[0].id
|
|
2832
|
-
}
|
|
2833
|
-
}
|
|
2834
|
-
},
|
|
2835
|
-
sort: ["createdAt:desc"]
|
|
2836
|
-
});
|
|
4175
|
+
} catch {
|
|
4176
|
+
ctx.status = 400;
|
|
4177
|
+
ctx.body = { error: "URL inválida." };
|
|
4178
|
+
return;
|
|
2837
4179
|
}
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
4180
|
+
const response = await axios.get(url, { responseType: "arraybuffer" });
|
|
4181
|
+
const base64 = Buffer.from(response.data).toString("base64");
|
|
4182
|
+
const contentType = response.headers["content-type"] || "application/octet-stream";
|
|
4183
|
+
ctx.body = { base64, contentType };
|
|
2842
4184
|
},
|
|
2843
4185
|
// ───────────────────────────────
|
|
2844
4186
|
// 🏞️ Internal File Upload Helper
|
|
2845
4187
|
// ───────────────────────────────
|
|
2846
4188
|
async _uploadGeneratedFile(file, filename, mimeType, folderName = "Generated") {
|
|
2847
|
-
const
|
|
2848
|
-
filters: { name: folderName }
|
|
2849
|
-
});
|
|
2850
|
-
let folderId;
|
|
2851
|
-
if (!existingFolders || existingFolders.length === 0) {
|
|
2852
|
-
const lastFolder = await strapi.documents("plugin::upload.folder").findMany({
|
|
2853
|
-
sort: { pathId: "desc" },
|
|
2854
|
-
limit: 1
|
|
2855
|
-
});
|
|
2856
|
-
const pathId = Array.isArray(lastFolder) && lastFolder.length > 0 ? lastFolder[0].pathId + 1 : 1;
|
|
2857
|
-
const createdFolder = await strapi.documents("plugin::upload.folder").create({
|
|
2858
|
-
data: {
|
|
2859
|
-
name: folderName,
|
|
2860
|
-
path: `/${folderName.toLowerCase()}`,
|
|
2861
|
-
pathId
|
|
2862
|
-
}
|
|
2863
|
-
});
|
|
2864
|
-
folderId = createdFolder.id;
|
|
2865
|
-
} else {
|
|
2866
|
-
folderId = existingFolders[0].id;
|
|
2867
|
-
}
|
|
4189
|
+
const folderId = await ensureFolder(strapi, folderName);
|
|
2868
4190
|
let fileSize = 0;
|
|
2869
4191
|
if (typeof file === "string") {
|
|
2870
4192
|
const stats = fs__namespace.statSync(file);
|
|
@@ -3099,15 +4421,7 @@ const service = ({ strapi }) => {
|
|
|
3099
4421
|
output_format: "image/png"
|
|
3100
4422
|
};
|
|
3101
4423
|
const promptText = JSON.stringify(promptJson);
|
|
3102
|
-
const generatedBase64Image = await
|
|
3103
|
-
promptText,
|
|
3104
|
-
aspectRatio || "16:9",
|
|
3105
|
-
// Use provided aspectRatio or default
|
|
3106
|
-
imageSize || "1K",
|
|
3107
|
-
// Use provided imageSize or default
|
|
3108
|
-
[]
|
|
3109
|
-
// No reference images for article generation
|
|
3110
|
-
);
|
|
4424
|
+
const generatedBase64Image = await strapi.plugin("strapi-content-generator-gemini").service("image-studio").generateForArticle(promptText, aspectRatio || "16:9", imageSize || "1K");
|
|
3111
4425
|
const buffer = Buffer.from(generatedBase64Image, "base64");
|
|
3112
4426
|
const uploadedFile = await this._uploadGeneratedFile(buffer, `article-${articleId}.png`, "image/png");
|
|
3113
4427
|
const articleModel = await strapi.getModel("api::articulo.articulo");
|
|
@@ -3130,134 +4444,10 @@ const service = ({ strapi }) => {
|
|
|
3130
4444
|
throw new Error("Error al generar la imagen para el artículo.");
|
|
3131
4445
|
}
|
|
3132
4446
|
},
|
|
3133
|
-
// ───────────────────────────────
|
|
3134
|
-
// 🖼️ Internal Image Generation Helper
|
|
3135
|
-
// Imagen 4 cuando no hay imágenes de referencia (mejor calidad y adherencia al prompt)
|
|
3136
|
-
// Gemini 2.5 Flash como fallback cuando se proporcionan imágenes de referencia
|
|
3137
|
-
// ───────────────────────────────
|
|
3138
|
-
async _callGeminiImageGeneration(promptText, aspectRatio, imageSizeLabel, referenceImages) {
|
|
3139
|
-
const ai = await this.geminiConfig();
|
|
3140
|
-
const cleanPrompt = promptText.replace(/\r\n/g, " ").replace(/\n/g, " ").replace(/\s+/g, " ").trim();
|
|
3141
|
-
if (referenceImages.length === 0) {
|
|
3142
|
-
const response = await ai.models.generateImages({
|
|
3143
|
-
model: "imagen-4.0-generate-001",
|
|
3144
|
-
prompt: cleanPrompt,
|
|
3145
|
-
config: {
|
|
3146
|
-
numberOfImages: 1,
|
|
3147
|
-
aspectRatio,
|
|
3148
|
-
outputMimeType: "image/png"
|
|
3149
|
-
}
|
|
3150
|
-
});
|
|
3151
|
-
const imageBytes = response.generatedImages?.[0]?.image?.imageBytes;
|
|
3152
|
-
if (!imageBytes) {
|
|
3153
|
-
throw new Error("Imagen 4 no devolvió imagen. Verifica el prompt o el modelo.");
|
|
3154
|
-
}
|
|
3155
|
-
return imageBytes;
|
|
3156
|
-
}
|
|
3157
|
-
const imageParts = referenceImages.map((img) => ({
|
|
3158
|
-
inlineData: {
|
|
3159
|
-
mimeType: img.mimeType,
|
|
3160
|
-
data: img.buffer.toString("base64")
|
|
3161
|
-
}
|
|
3162
|
-
}));
|
|
3163
|
-
const result = await ai.models.generateContent({
|
|
3164
|
-
model: "gemini-2.5-flash-image",
|
|
3165
|
-
contents: [{ text: cleanPrompt }, ...imageParts],
|
|
3166
|
-
config: {
|
|
3167
|
-
responseModalities: [genai.Modality.IMAGE],
|
|
3168
|
-
imageConfig: { aspectRatio, imageSize: imageSizeLabel }
|
|
3169
|
-
}
|
|
3170
|
-
});
|
|
3171
|
-
const parts = result?.candidates?.[0]?.content?.parts;
|
|
3172
|
-
if (!Array.isArray(parts)) {
|
|
3173
|
-
throw new Error("Respuesta inválida del modelo (parts no encontrado)");
|
|
3174
|
-
}
|
|
3175
|
-
const imagePart = parts.find(
|
|
3176
|
-
(p) => p?.inlineData?.data && typeof p.inlineData.data === "string" && p.inlineData.mimeType?.startsWith("image/")
|
|
3177
|
-
);
|
|
3178
|
-
if (!imagePart) {
|
|
3179
|
-
throw new Error("No se encontró ninguna imagen en la respuesta del modelo");
|
|
3180
|
-
}
|
|
3181
|
-
return imagePart.inlineData.data;
|
|
3182
|
-
},
|
|
3183
|
-
// ───────────────────────────────
|
|
3184
|
-
// 🖼️ Generate Image (Standalone)
|
|
3185
|
-
// ───────────────────────────────
|
|
3186
|
-
async generateImage(ctx) {
|
|
3187
|
-
const { prompt, aspectRatio, imageSize } = ctx.request.body;
|
|
3188
|
-
if (!prompt) {
|
|
3189
|
-
throw new Error("Se requiere 'prompt' para generar el contenido visual.");
|
|
3190
|
-
}
|
|
3191
|
-
const promptJson = {
|
|
3192
|
-
label: `standalone-image-${Date.now()}`,
|
|
3193
|
-
task: "generate_image",
|
|
3194
|
-
canvas: {
|
|
3195
|
-
resolution: imageSize || "1K",
|
|
3196
|
-
aspect_ratio: aspectRatio || "16:9"
|
|
3197
|
-
},
|
|
3198
|
-
style: {
|
|
3199
|
-
type: "architectural software engineering visualization",
|
|
3200
|
-
aesthetic: "high-end technical 3D render / octane style",
|
|
3201
|
-
background: "view of a bright white minimalist architectural gallery, sun-drenched space, white polished floors and tall glass windows",
|
|
3202
|
-
lighting: "intense natural daylight, soft global illumination, clean diffused light with subtle volumetric rays from windows"
|
|
3203
|
-
},
|
|
3204
|
-
concept_brief: prompt,
|
|
3205
|
-
subject: [
|
|
3206
|
-
"apply the concept brief above as the main subject — rendered as a sophisticated 3D holographic or architectural structure floating inside the gallery",
|
|
3207
|
-
"materials: frosted glass, white matte ceramic, polished metal accents",
|
|
3208
|
-
"brand accent colors red #E4002B and teal #00C7B1 on glowing energy filaments, highlights, and data connections",
|
|
3209
|
-
"the structure casts a sharp, clean reflection on the white polished gallery floor",
|
|
3210
|
-
"STRICTLY NO people, NO humans, NO hands, NO chairs",
|
|
3211
|
-
"STRICTLY NO text, NO labels, NO words, NO letters, NO numbers, NO logos",
|
|
3212
|
-
"high-end 3D render, architectural photography style, 4k quality"
|
|
3213
|
-
],
|
|
3214
|
-
camera: {
|
|
3215
|
-
perspective: "three-quarter wide shot, slightly elevated, showing both the subject and the gallery environment",
|
|
3216
|
-
depth_of_field: "main subject in sharp focus, gallery background beautifully blurred"
|
|
3217
|
-
},
|
|
3218
|
-
render: {
|
|
3219
|
-
engine: "Octane or Cinema 4D",
|
|
3220
|
-
effects: "bloom on glowing elements, ray-traced reflections on the white polished floor, subsurface scattering on frosted glass, volumetric light rays from gallery windows",
|
|
3221
|
-
quality: "masterpiece, hyper-detailed"
|
|
3222
|
-
},
|
|
3223
|
-
output_format: "image/png"
|
|
3224
|
-
};
|
|
3225
|
-
const basePrompt = JSON.stringify(promptJson);
|
|
3226
|
-
const files = ctx.request.files ?? {};
|
|
3227
|
-
const referenceImages = Object.entries(files).filter(([key]) => key.startsWith("referenceImages")).map(([, file]) => file);
|
|
3228
|
-
if (referenceImages.length > 5) {
|
|
3229
|
-
throw new Error("Máximo 5 imágenes de referencia permitidas.");
|
|
3230
|
-
}
|
|
3231
|
-
const imageBuffers = referenceImages.map((file) => {
|
|
3232
|
-
const typedFile = file;
|
|
3233
|
-
return {
|
|
3234
|
-
buffer: typedFile.buffer ?? fs__namespace.readFileSync(typedFile.filepath),
|
|
3235
|
-
mimeType: typedFile.mimetype
|
|
3236
|
-
};
|
|
3237
|
-
});
|
|
3238
|
-
try {
|
|
3239
|
-
const generatedBase64Image = await this._callGeminiImageGeneration(
|
|
3240
|
-
basePrompt,
|
|
3241
|
-
aspectRatio || "16:9",
|
|
3242
|
-
imageSize || "1K",
|
|
3243
|
-
imageBuffers
|
|
3244
|
-
);
|
|
3245
|
-
const buffer = Buffer.from(generatedBase64Image, "base64");
|
|
3246
|
-
const filename = `generated-image-${Date.now()}.png`;
|
|
3247
|
-
const uploadedFile = await this._uploadGeneratedFile(buffer, filename, "image/png");
|
|
3248
|
-
return {
|
|
3249
|
-
message: `Imagen generada y subida correctamente.`,
|
|
3250
|
-
file: uploadedFile
|
|
3251
|
-
};
|
|
3252
|
-
} catch (err) {
|
|
3253
|
-
console.error("🚀 ~ generateImage ~ err:", err);
|
|
3254
|
-
throw new Error(`Error al generar la imagen.`);
|
|
3255
|
-
}
|
|
3256
|
-
},
|
|
3257
4447
|
// 🎞️ Internal Veo Video Generation / Extension Helper
|
|
3258
4448
|
async _callVeoVideoGeneration(promptText, aspectRatio, durationSeconds, sceneRefs, previousVideo) {
|
|
3259
4449
|
const ai = await this.geminiConfig();
|
|
3260
|
-
const
|
|
4450
|
+
const cleanPrompt2 = promptText.replace(/\s+/g, " ").trim();
|
|
3261
4451
|
const referenceImages = sceneRefs.map((img) => ({
|
|
3262
4452
|
image: {
|
|
3263
4453
|
imageBytes: img.buffer.toString("base64"),
|
|
@@ -3274,7 +4464,7 @@ const service = ({ strapi }) => {
|
|
|
3274
4464
|
};
|
|
3275
4465
|
const operationParams = {
|
|
3276
4466
|
model: "veo-3.1-generate-preview",
|
|
3277
|
-
prompt:
|
|
4467
|
+
prompt: cleanPrompt2,
|
|
3278
4468
|
config: config2
|
|
3279
4469
|
};
|
|
3280
4470
|
if (previousVideo) {
|
|
@@ -3506,13 +4696,15 @@ ${hashtags}`,
|
|
|
3506
4696
|
};
|
|
3507
4697
|
};
|
|
3508
4698
|
const services = {
|
|
3509
|
-
service
|
|
4699
|
+
service,
|
|
4700
|
+
"image-studio": imageStudio$1,
|
|
4701
|
+
templates: templates$1
|
|
3510
4702
|
};
|
|
3511
4703
|
const index = {
|
|
3512
4704
|
register,
|
|
3513
4705
|
bootstrap,
|
|
3514
4706
|
destroy,
|
|
3515
|
-
config: config$
|
|
4707
|
+
config: config$2,
|
|
3516
4708
|
controllers,
|
|
3517
4709
|
routes,
|
|
3518
4710
|
services,
|