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