@ozguraltan/strapi-content-input 1.0.12 → 1.0.22
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 +187 -54
- package/dist/admin/{AnalyticsHubPage-DNREITPq.js → AnalyticsHubPage-B1_chQkG.js} +60 -9
- package/dist/admin/{AnalyticsHubPage-Dj4roAe0.mjs → AnalyticsHubPage-DUj3D2kA.mjs} +60 -9
- package/dist/admin/{ContentInputField-Ko-r12jl.mjs → ContentInputField-BrtpTCDd.mjs} +11898 -903
- package/dist/admin/{ContentInputField-2hk9xG8p.js → ContentInputField-CQFQxxgm.js} +11934 -921
- package/dist/admin/{SurveyWidgetEditor-B3F4DE5r.js → SurveyWidgetEditor-C5Uvyf_h.js} +3992 -1086
- package/dist/admin/{SurveyWidgetEditor-B1S83aBE.mjs → SurveyWidgetEditor-DGSwgTzR.mjs} +4012 -1107
- package/dist/admin/{en-bneQpRJa.js → en-BZg845za.js} +2 -2
- package/dist/admin/{en-DnLdDKyq.mjs → en-C9LN2PJY.mjs} +2 -2
- package/dist/admin/{index-gn-4eO6g.mjs → index-Dc7AFLOj.mjs} +16 -6
- package/dist/admin/{index-B4FpXxnK.js → index-i0NfSYto.js} +16 -6
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/components/color-codes/ColorCodesManager.d.ts +10 -0
- package/dist/admin/src/components/common/CIAspectRatioField.d.ts +35 -0
- package/dist/admin/src/components/common/CIColorField.d.ts +13 -0
- package/dist/admin/src/components/common/CIImageSettingsControl.d.ts +17 -0
- package/dist/admin/src/components/widgets/CustomCardWidgetEditor.d.ts +84 -0
- package/dist/admin/src/components/widgets/DataTableWidgetEditor.d.ts +65 -0
- package/dist/admin/src/components/widgets/EntityCardWidgetEditor.d.ts +10 -0
- package/dist/admin/src/components/widgets/HeroSliderStage.d.ts +156 -0
- package/dist/admin/src/components/widgets/HeroSliderWidgetEditor.d.ts +21 -0
- package/dist/admin/src/components/widgets/StrapiMediaPicker.d.ts +2 -0
- package/dist/admin/src/components/widgets/SurveyWidgetEditor.d.ts +1 -1
- package/dist/admin/src/core/canvasClasses.d.ts +1 -0
- package/dist/admin/src/core/colorUtils.d.ts +30 -0
- package/dist/admin/src/core/sampleData.d.ts +2 -1
- package/dist/admin/src/core/types.d.ts +12 -0
- package/dist/admin/src/core/useColorCodes.d.ts +43 -0
- package/dist/admin/{tr-00QqO0E7.mjs → tr-MtQFY92V.mjs} +2 -2
- package/dist/admin/{tr-O0nhB9er.js → tr-ZEmzAvKR.js} +2 -2
- package/dist/server/index.js +2162 -286
- package/dist/server/index.mjs +2162 -286
- package/dist/server/src/config/index.d.ts +4 -0
- package/dist/server/src/content-types/ci-color-palette/schema.json.d.ts +52 -0
- package/dist/server/src/content-types/index.d.ts +50 -0
- package/dist/server/src/controllers/ci-color.d.ts +14 -0
- package/dist/server/src/controllers/ci-image.d.ts +11 -2
- package/dist/server/src/controllers/index.d.ts +13 -0
- package/dist/server/src/index.d.ts +124 -0
- package/dist/server/src/services/ci-color.d.ts +127 -0
- package/dist/server/src/services/index.d.ts +57 -0
- package/dist/server/src/utils/image-variants.d.ts +74 -0
- package/dist/server/src/utils/mailer.d.ts +1 -0
- package/package.json +3 -2
package/dist/server/index.js
CHANGED
|
@@ -20,31 +20,987 @@ const register = ({ strapi }) => {
|
|
|
20
20
|
isResizable: false
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
+
if (strapi?.server?.use) {
|
|
24
|
+
strapi.server.use(async (ctx, next) => {
|
|
25
|
+
await next();
|
|
26
|
+
const csp = ctx?.response?.get?.("Content-Security-Policy");
|
|
27
|
+
if (typeof csp === "string" && csp.includes("frame-src")) {
|
|
28
|
+
const updated = csp.replace(/frame-src\s+([^;]+)/i, (match, sources) => {
|
|
29
|
+
if (sources.includes("https:") || sources.includes("*")) return match;
|
|
30
|
+
return `frame-src ${sources.trim()} https: http: data: blob:`;
|
|
31
|
+
});
|
|
32
|
+
if (updated !== csp) {
|
|
33
|
+
ctx.set("Content-Security-Policy", updated);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
23
38
|
};
|
|
39
|
+
const inFlightVariants = /* @__PURE__ */ new Map();
|
|
40
|
+
function getSharp() {
|
|
41
|
+
const req = typeof require !== "undefined" ? require : module$1.createRequire(path__default.default.join(process.cwd(), "package.json"));
|
|
42
|
+
return req("sharp");
|
|
43
|
+
}
|
|
44
|
+
function getVariantConfig(strapi) {
|
|
45
|
+
const pluginCfg = strapi?.config?.get?.("plugin::content-input") || {};
|
|
46
|
+
const envFolder = process.env.CI_IMAGE_VARIANT_FOLDER;
|
|
47
|
+
const rawFolder = envFolder !== void 0 && String(envFolder).trim() !== "" ? String(envFolder).trim() : pluginCfg.imageVariantFolder !== void 0 ? pluginCfg.imageVariantFolder : "ci-optimized";
|
|
48
|
+
let folder = "ci-optimized";
|
|
49
|
+
if (rawFolder === null || rawFolder === false || String(rawFolder).trim().toLowerCase() === "none" || String(rawFolder).trim() === "/") {
|
|
50
|
+
folder = null;
|
|
51
|
+
} else {
|
|
52
|
+
const cleaned = String(rawFolder).trim().replace(/^\/+|\/+$/g, "");
|
|
53
|
+
folder = cleaned || "ci-optimized";
|
|
54
|
+
}
|
|
55
|
+
const rawFmt = String(
|
|
56
|
+
process.env.CI_IMAGE_VARIANT_FORMAT || pluginCfg.imageVariantFormat || "webp"
|
|
57
|
+
).trim().toLowerCase();
|
|
58
|
+
const defaultFormat = rawFmt === "auto" ? "auto" : "webp";
|
|
59
|
+
const envRedirect = process.env.CI_IMAGE_REDIRECT_CDN;
|
|
60
|
+
const redirectProxyToCdn = envRedirect !== void 0 ? envRedirect !== "0" && envRedirect.toLowerCase() !== "false" : pluginCfg.redirectProxyToCdn !== false;
|
|
61
|
+
const defaultQuality = Math.min(
|
|
62
|
+
100,
|
|
63
|
+
Math.max(40, Number(pluginCfg.imageVariantQuality) || 85)
|
|
64
|
+
);
|
|
65
|
+
return {
|
|
66
|
+
folder,
|
|
67
|
+
defaultFormat,
|
|
68
|
+
redirectProxyToCdn,
|
|
69
|
+
defaultQuality
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function isAbsoluteHttpUrl(url) {
|
|
73
|
+
return Boolean(url && /^https?:\/\//i.test(String(url).trim()));
|
|
74
|
+
}
|
|
75
|
+
function isOptimizableRasterImage(mime, urlOrName) {
|
|
76
|
+
const m = String(mime || "").trim().toLowerCase();
|
|
77
|
+
const u = String(urlOrName || "").split("?")[0].split("#")[0].trim().toLowerCase();
|
|
78
|
+
if (u.startsWith("data:") || u.startsWith("blob:")) return false;
|
|
79
|
+
if (m.includes("svg") || m.includes("gif") || m.startsWith("video/") || m.startsWith("audio/") || m.startsWith("application/") || m.startsWith("text/")) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (/\.(svg|gif|mp4|webm|mov|m4v|mp3|wav|ogg|pdf|docx?|xlsx?|pptx?|zip|rar)$/i.test(u)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
if (m === "image/jpeg" || m === "image/jpg" || m === "image/png" || m === "image/webp" || m === "image/avif" || m === "image/tiff" || m === "image/bmp") {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
if (/\.(jpe?g|png|webp|avif|tiff?|bmp)$/i.test(u)) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
if (m.startsWith("image/")) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
async function loadSourceBuffer(strapi, src) {
|
|
97
|
+
const publicDir = strapi?.dirs?.static?.public || path__default.default.join(process.cwd(), "public");
|
|
98
|
+
if (src.startsWith("/")) {
|
|
99
|
+
const cleanRel = decodeURIComponent(src.split("?")[0]).replace(/^\/+/, "");
|
|
100
|
+
const fullPath = path__default.default.resolve(publicDir, cleanRel);
|
|
101
|
+
const resolvedPublic = path__default.default.resolve(publicDir);
|
|
102
|
+
if (!fullPath.startsWith(resolvedPublic)) {
|
|
103
|
+
throw new Error("Invalid local file path");
|
|
104
|
+
}
|
|
105
|
+
if (!fs__default.default.existsSync(fullPath)) {
|
|
106
|
+
throw new Error(`File not found: ${src}`);
|
|
107
|
+
}
|
|
108
|
+
const buffer = await fs__default.default.promises.readFile(fullPath);
|
|
109
|
+
const ext = path__default.default.extname(fullPath).toLowerCase();
|
|
110
|
+
const mime = ext === ".png" ? "image/png" : ext === ".webp" ? "image/webp" : ext === ".avif" ? "image/avif" : ext === ".gif" ? "image/gif" : "image/jpeg";
|
|
111
|
+
return { buffer, mime };
|
|
112
|
+
}
|
|
113
|
+
if (/^https?:\/\//i.test(src)) {
|
|
114
|
+
const parsed = new URL(src);
|
|
115
|
+
if ((parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1") && parsed.pathname.startsWith("/uploads/")) {
|
|
116
|
+
const cleanRel = decodeURIComponent(parsed.pathname).replace(/^\/+/, "");
|
|
117
|
+
const fullPath = path__default.default.resolve(publicDir, cleanRel);
|
|
118
|
+
if (fs__default.default.existsSync(fullPath)) {
|
|
119
|
+
const buffer = await fs__default.default.promises.readFile(fullPath);
|
|
120
|
+
const ext = path__default.default.extname(fullPath).toLowerCase();
|
|
121
|
+
const mime = ext === ".png" ? "image/png" : ext === ".webp" ? "image/webp" : "image/jpeg";
|
|
122
|
+
return { buffer, mime };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const res = await fetch(src);
|
|
126
|
+
if (!res.ok) {
|
|
127
|
+
throw new Error(`Failed to fetch remote image (${res.status})`);
|
|
128
|
+
}
|
|
129
|
+
const contentType = res.headers.get("content-type") || "image/jpeg";
|
|
130
|
+
const arr = await res.arrayBuffer();
|
|
131
|
+
return { buffer: Buffer.from(arr), mime: contentType };
|
|
132
|
+
}
|
|
133
|
+
throw new Error("Unsupported image source URL");
|
|
134
|
+
}
|
|
135
|
+
function normalizeImageProcessSpec(imageSettings, defaultAutoMaxW = 1920) {
|
|
136
|
+
const safeMaxW = Math.min(3840, Math.max(64, Math.round(Number(defaultAutoMaxW) || 1920)));
|
|
137
|
+
const rawProc = String(imageSettings?.process ?? "").trim().toLowerCase();
|
|
138
|
+
const rotate = parseInt(String(imageSettings?.rotate || "0"), 10) || 0;
|
|
139
|
+
const q = Math.min(100, Math.max(30, parseInt(String(imageSettings?.quality || "85"), 10) || 85));
|
|
140
|
+
if (rawProc === "none" || rawProc === "no-process" || rawProc === "original") {
|
|
141
|
+
return {
|
|
142
|
+
processMode: "none",
|
|
143
|
+
w: 0,
|
|
144
|
+
h: 0,
|
|
145
|
+
maxW: safeMaxW,
|
|
146
|
+
q,
|
|
147
|
+
rotate: 0
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (rawProc === "fit") {
|
|
151
|
+
const w = Math.min(3840, Math.max(0, Math.round(Number(imageSettings?.cWidth) || 0)));
|
|
152
|
+
const h = Math.min(3840, Math.max(0, Math.round(Number(imageSettings?.cHeight) || 0)));
|
|
153
|
+
if (w > 0 && h > 0) {
|
|
154
|
+
return { processMode: "fit", w, h, maxW: safeMaxW, q, rotate };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (rawProc === "widen") {
|
|
158
|
+
const w = Math.min(3840, Math.max(0, Math.round(Number(imageSettings?.cWidth) || 0)));
|
|
159
|
+
if (w > 0) {
|
|
160
|
+
return { processMode: "widen", w, h: 0, maxW: safeMaxW, q, rotate };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const customAutoW = Number(imageSettings?.maxWidth || imageSettings?.cWidth);
|
|
164
|
+
const autoW = rawProc === "auto" && customAutoW > 0 ? Math.min(3840, Math.max(64, Math.round(customAutoW))) : safeMaxW;
|
|
165
|
+
return {
|
|
166
|
+
processMode: "auto",
|
|
167
|
+
w: autoW,
|
|
168
|
+
h: 0,
|
|
169
|
+
maxW: autoW,
|
|
170
|
+
q,
|
|
171
|
+
rotate
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function computeCiFormatKey(processMode, w, h, rotate = 0) {
|
|
175
|
+
const effH = processMode === "fit" ? h : 0;
|
|
176
|
+
const effW = w;
|
|
177
|
+
return `ci_${processMode}_${effW}x${effH}${rotate ? `_r${rotate}` : ""}`;
|
|
178
|
+
}
|
|
179
|
+
function compactAssetFormats(formats) {
|
|
180
|
+
if (!formats || typeof formats !== "object") return void 0;
|
|
181
|
+
const out = {};
|
|
182
|
+
const keepStandard = /* @__PURE__ */ new Set(["thumbnail", "small", "medium", "large"]);
|
|
183
|
+
for (const [key, val] of Object.entries(formats)) {
|
|
184
|
+
if (!val || typeof val !== "object" || typeof val.url !== "string" || !val.url) continue;
|
|
185
|
+
if (!keepStandard.has(key) && !key.startsWith("ci_")) continue;
|
|
186
|
+
out[key] = {
|
|
187
|
+
url: val.url,
|
|
188
|
+
...val.width ? { width: Number(val.width) } : {},
|
|
189
|
+
...val.height ? { height: Number(val.height) } : {},
|
|
190
|
+
...val.mime ? { mime: String(val.mime) } : {},
|
|
191
|
+
...val.size ? { size: Number(val.size) } : {}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
195
|
+
}
|
|
196
|
+
function stripVariantPrefixFromHash(baseNameNoExt) {
|
|
197
|
+
return baseNameNoExt.replace(/^ci_(?:fit|widen|auto)_\d+x\d+(?:_r-?\d+)?_/, "");
|
|
198
|
+
}
|
|
199
|
+
async function findUploadFileForAsset(strapi, assetOrUrl, cache) {
|
|
200
|
+
if (!assetOrUrl) return null;
|
|
201
|
+
const fileQuery = strapi.db.query("plugin::upload.file");
|
|
202
|
+
const isObj = typeof assetOrUrl === "object";
|
|
203
|
+
const rawId = isObj ? assetOrUrl.id : void 0;
|
|
204
|
+
const rawHash = isObj ? assetOrUrl.hash : void 0;
|
|
205
|
+
const rawUrl = isObj ? assetOrUrl.original_url || assetOrUrl.url || assetOrUrl.target_url || assetOrUrl.src || "" : String(assetOrUrl || "");
|
|
206
|
+
const cleanUrl = String(rawUrl || "").split("?")[0].split("#")[0].trim();
|
|
207
|
+
const cacheKey = rawId ? `id:${rawId}` : rawHash ? `hash:${rawHash}` : cleanUrl ? `url:${cleanUrl}` : "";
|
|
208
|
+
if (cache && cacheKey && cache.has(cacheKey)) {
|
|
209
|
+
return cache.get(cacheKey);
|
|
210
|
+
}
|
|
211
|
+
let found = null;
|
|
212
|
+
const remember = (record) => {
|
|
213
|
+
if (cache) {
|
|
214
|
+
if (cacheKey) cache.set(cacheKey, record);
|
|
215
|
+
if (record?.id) cache.set(`id:${record.id}`, record);
|
|
216
|
+
if (record?.hash) cache.set(`hash:${record.hash}`, record);
|
|
217
|
+
if (record?.url) cache.set(`url:${String(record.url).split("?")[0]}`, record);
|
|
218
|
+
}
|
|
219
|
+
return record;
|
|
220
|
+
};
|
|
221
|
+
if (rawId !== void 0 && rawId !== null && rawId !== "") {
|
|
222
|
+
const numId = Number(rawId);
|
|
223
|
+
if (!Number.isNaN(numId) && numId > 0) {
|
|
224
|
+
found = await fileQuery.findOne({ where: { id: numId } });
|
|
225
|
+
if (found) return remember(found);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (rawHash && typeof rawHash === "string") {
|
|
229
|
+
const parentHash = stripVariantPrefixFromHash(rawHash.trim());
|
|
230
|
+
found = await fileQuery.findOne({ where: { hash: parentHash } });
|
|
231
|
+
if (found) return remember(found);
|
|
232
|
+
}
|
|
233
|
+
if (!cleanUrl) return remember(null);
|
|
234
|
+
found = await fileQuery.findOne({ where: { url: cleanUrl } });
|
|
235
|
+
if (found) return remember(found);
|
|
236
|
+
let pathnameStr = cleanUrl;
|
|
237
|
+
if (/^https?:\/\//i.test(cleanUrl)) {
|
|
238
|
+
try {
|
|
239
|
+
pathnameStr = decodeURIComponent(new URL(cleanUrl).pathname);
|
|
240
|
+
} catch {
|
|
241
|
+
pathnameStr = cleanUrl;
|
|
242
|
+
}
|
|
243
|
+
if (pathnameStr && pathnameStr !== cleanUrl) {
|
|
244
|
+
found = await fileQuery.findOne({ where: { url: pathnameStr } });
|
|
245
|
+
if (found) return remember(found);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const baseName = path__default.default.posix.basename(pathnameStr);
|
|
249
|
+
const ext = path__default.default.posix.extname(baseName);
|
|
250
|
+
const baseNoExt = ext ? baseName.slice(0, -ext.length) : baseName;
|
|
251
|
+
if (baseNoExt) {
|
|
252
|
+
const candidateHash = stripVariantPrefixFromHash(baseNoExt);
|
|
253
|
+
if (candidateHash) {
|
|
254
|
+
found = await fileQuery.findOne({ where: { hash: candidateHash } });
|
|
255
|
+
if (found) return remember(found);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return remember(null);
|
|
259
|
+
}
|
|
260
|
+
async function renderSharpVariantBuffer(sourceBuffer, sourceMime, opts) {
|
|
261
|
+
const sharp = getSharp();
|
|
262
|
+
let pipeline = sharp(sourceBuffer, { failOn: "none" }).rotate();
|
|
263
|
+
const rotate = opts.rotate || 0;
|
|
264
|
+
if (rotate && [90, 180, 270, -90].includes(rotate)) {
|
|
265
|
+
pipeline = pipeline.rotate(rotate);
|
|
266
|
+
}
|
|
267
|
+
const cw = opts.cw || 0;
|
|
268
|
+
const ch = opts.ch || 0;
|
|
269
|
+
if (cw > 0 && ch > 0) {
|
|
270
|
+
pipeline = pipeline.extract({
|
|
271
|
+
left: Math.max(0, opts.cx || 0),
|
|
272
|
+
top: Math.max(0, opts.cy || 0),
|
|
273
|
+
width: cw,
|
|
274
|
+
height: ch
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const { processMode, w, h, q } = opts;
|
|
278
|
+
if (processMode === "fit" && w > 0 && h > 0) {
|
|
279
|
+
pipeline = pipeline.resize(w, h, {
|
|
280
|
+
fit: "cover",
|
|
281
|
+
position: "centre",
|
|
282
|
+
withoutEnlargement: false
|
|
283
|
+
});
|
|
284
|
+
} else if (processMode === "widen" && w > 0) {
|
|
285
|
+
pipeline = pipeline.resize(w, null, {
|
|
286
|
+
fit: "inside",
|
|
287
|
+
withoutEnlargement: false
|
|
288
|
+
});
|
|
289
|
+
} else if (processMode === "auto" && w > 0) {
|
|
290
|
+
pipeline = pipeline.resize(w, null, {
|
|
291
|
+
fit: "inside",
|
|
292
|
+
withoutEnlargement: true
|
|
293
|
+
});
|
|
294
|
+
} else if (w > 0 || h > 0) {
|
|
295
|
+
pipeline = pipeline.resize(w || null, h || null, {
|
|
296
|
+
fit: "inside",
|
|
297
|
+
withoutEnlargement: true
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
const reqFmt = String(opts.requestedFormat || "").trim().toLowerCase();
|
|
301
|
+
const preferWebp = reqFmt === "webp" || !reqFmt && (opts.defaultFormat || "webp") === "webp";
|
|
302
|
+
let contentType = sourceMime || "image/webp";
|
|
303
|
+
let ext = ".webp";
|
|
304
|
+
if (reqFmt === "avif") {
|
|
305
|
+
pipeline = pipeline.avif({ quality: q });
|
|
306
|
+
contentType = "image/avif";
|
|
307
|
+
ext = ".avif";
|
|
308
|
+
} else if (reqFmt === "png") {
|
|
309
|
+
pipeline = pipeline.png({ quality: q });
|
|
310
|
+
contentType = "image/png";
|
|
311
|
+
ext = ".png";
|
|
312
|
+
} else if (reqFmt === "jpg" || reqFmt === "jpeg") {
|
|
313
|
+
pipeline = pipeline.jpeg({ quality: q, mozjpeg: true });
|
|
314
|
+
contentType = "image/jpeg";
|
|
315
|
+
ext = ".jpg";
|
|
316
|
+
} else if (preferWebp || sourceMime === "image/webp") {
|
|
317
|
+
pipeline = pipeline.webp({ quality: q, alphaQuality: 100, effort: 4 });
|
|
318
|
+
contentType = "image/webp";
|
|
319
|
+
ext = ".webp";
|
|
320
|
+
} else if (sourceMime === "image/avif") {
|
|
321
|
+
pipeline = pipeline.avif({ quality: q });
|
|
322
|
+
contentType = "image/avif";
|
|
323
|
+
ext = ".avif";
|
|
324
|
+
} else if (sourceMime === "image/png") {
|
|
325
|
+
pipeline = pipeline.png({ quality: q });
|
|
326
|
+
contentType = "image/png";
|
|
327
|
+
ext = ".png";
|
|
328
|
+
} else {
|
|
329
|
+
pipeline = pipeline.jpeg({ quality: q, mozjpeg: true });
|
|
330
|
+
contentType = "image/jpeg";
|
|
331
|
+
ext = ".jpg";
|
|
332
|
+
}
|
|
333
|
+
const outputBuffer = await pipeline.toBuffer();
|
|
334
|
+
const outMeta = await sharp(outputBuffer).metadata();
|
|
335
|
+
return {
|
|
336
|
+
buffer: outputBuffer,
|
|
337
|
+
contentType,
|
|
338
|
+
ext,
|
|
339
|
+
width: outMeta.width || w || void 0,
|
|
340
|
+
height: outMeta.height || h || void 0
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
async function ensureMediaVariant(strapi, existingFile, spec) {
|
|
344
|
+
const formatKey = computeCiFormatKey(
|
|
345
|
+
spec.processMode,
|
|
346
|
+
spec.w,
|
|
347
|
+
spec.h,
|
|
348
|
+
spec.rotate || 0
|
|
349
|
+
);
|
|
350
|
+
if (!existingFile?.id || !existingFile?.url) {
|
|
351
|
+
return { formatKey, formatEntry: null, updatedFile: existingFile };
|
|
352
|
+
}
|
|
353
|
+
if (!isOptimizableRasterImage(existingFile.mime, existingFile.ext || existingFile.url)) {
|
|
354
|
+
return { formatKey, formatEntry: null, updatedFile: existingFile };
|
|
355
|
+
}
|
|
356
|
+
const already = existingFile.formats?.[formatKey];
|
|
357
|
+
if (already?.url) {
|
|
358
|
+
return { formatKey, formatEntry: already, updatedFile: existingFile };
|
|
359
|
+
}
|
|
360
|
+
const lockKey = `${existingFile.id}:${formatKey}`;
|
|
361
|
+
const activePromise = inFlightVariants.get(lockKey);
|
|
362
|
+
if (activePromise) {
|
|
363
|
+
return activePromise;
|
|
364
|
+
}
|
|
365
|
+
const task = (async () => {
|
|
366
|
+
const cfg = getVariantConfig(strapi);
|
|
367
|
+
const freshCheck = await strapi.db.query("plugin::upload.file").findOne({
|
|
368
|
+
where: { id: existingFile.id }
|
|
369
|
+
});
|
|
370
|
+
const baseRecord = freshCheck || existingFile;
|
|
371
|
+
if (baseRecord.formats?.[formatKey]?.url) {
|
|
372
|
+
return {
|
|
373
|
+
formatKey,
|
|
374
|
+
formatEntry: baseRecord.formats[formatKey],
|
|
375
|
+
updatedFile: baseRecord
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
const { buffer: sourceBuffer, mime: sourceMime } = await loadSourceBuffer(
|
|
379
|
+
strapi,
|
|
380
|
+
baseRecord.url
|
|
381
|
+
);
|
|
382
|
+
const rendered = await renderSharpVariantBuffer(
|
|
383
|
+
sourceBuffer,
|
|
384
|
+
baseRecord.mime || sourceMime,
|
|
385
|
+
{
|
|
386
|
+
processMode: spec.processMode,
|
|
387
|
+
w: spec.w,
|
|
388
|
+
h: spec.h,
|
|
389
|
+
q: spec.q || cfg.defaultQuality,
|
|
390
|
+
rotate: spec.rotate || 0,
|
|
391
|
+
requestedFormat: spec.requestedFormat,
|
|
392
|
+
defaultFormat: cfg.defaultFormat
|
|
393
|
+
}
|
|
394
|
+
);
|
|
395
|
+
const fallbackShortHash = crypto__default.default.createHash("sha1").update(String(baseRecord.url)).digest("hex").slice(0, 10);
|
|
396
|
+
const cleanBaseName = path__default.default.basename(
|
|
397
|
+
baseRecord.name || "image",
|
|
398
|
+
path__default.default.extname(baseRecord.name || "")
|
|
399
|
+
);
|
|
400
|
+
const variantHash = `${formatKey}_${baseRecord.hash || fallbackShortHash}`;
|
|
401
|
+
const variantName = `${formatKey}_${cleanBaseName}${rendered.ext}`;
|
|
402
|
+
const tmpVariantPath = path__default.default.join(
|
|
403
|
+
os__default.default.tmpdir(),
|
|
404
|
+
`${variantHash}_${Date.now()}_${Math.random().toString(36).slice(2, 6)}${rendered.ext}`
|
|
405
|
+
);
|
|
406
|
+
await fs__default.default.promises.writeFile(tmpVariantPath, rendered.buffer);
|
|
407
|
+
try {
|
|
408
|
+
const variantFile = {
|
|
409
|
+
name: variantName,
|
|
410
|
+
hash: variantHash,
|
|
411
|
+
ext: rendered.ext,
|
|
412
|
+
mime: rendered.contentType,
|
|
413
|
+
filepath: tmpVariantPath,
|
|
414
|
+
path: cfg.folder !== null ? cfg.folder : baseRecord.path || null,
|
|
415
|
+
getStream: () => fs__default.default.createReadStream(tmpVariantPath),
|
|
416
|
+
width: rendered.width,
|
|
417
|
+
height: rendered.height,
|
|
418
|
+
size: Math.round(rendered.buffer.length / 1e3 * 100) / 100,
|
|
419
|
+
sizeInBytes: rendered.buffer.length
|
|
420
|
+
};
|
|
421
|
+
const providerService = strapi.plugin("upload").service("provider");
|
|
422
|
+
if (!providerService || typeof providerService.upload !== "function") {
|
|
423
|
+
return { formatKey, formatEntry: null, updatedFile: baseRecord };
|
|
424
|
+
}
|
|
425
|
+
await providerService.upload(variantFile);
|
|
426
|
+
const { filepath: _fp, getStream: _gs, ...serializableFormat } = variantFile;
|
|
427
|
+
const latestRecord = await strapi.db.query("plugin::upload.file").findOne({
|
|
428
|
+
where: { id: baseRecord.id }
|
|
429
|
+
}) || baseRecord;
|
|
430
|
+
const nextFormats = {
|
|
431
|
+
...latestRecord.formats || {},
|
|
432
|
+
[formatKey]: serializableFormat
|
|
433
|
+
};
|
|
434
|
+
const updatedFile = await strapi.db.query("plugin::upload.file").update({
|
|
435
|
+
where: { id: baseRecord.id },
|
|
436
|
+
data: { formats: nextFormats }
|
|
437
|
+
});
|
|
438
|
+
existingFile.formats = nextFormats;
|
|
439
|
+
return {
|
|
440
|
+
formatKey,
|
|
441
|
+
formatEntry: serializableFormat,
|
|
442
|
+
updatedFile: updatedFile || { ...latestRecord, formats: nextFormats }
|
|
443
|
+
};
|
|
444
|
+
} finally {
|
|
445
|
+
await fs__default.default.promises.rm(tmpVariantPath, { force: true }).catch(() => void 0);
|
|
446
|
+
}
|
|
447
|
+
})();
|
|
448
|
+
inFlightVariants.set(lockKey, task);
|
|
449
|
+
try {
|
|
450
|
+
return await task;
|
|
451
|
+
} finally {
|
|
452
|
+
inFlightVariants.delete(lockKey);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
async function clearGeneratedCiVariantsForFile(strapi, fileRecord) {
|
|
456
|
+
if (!fileRecord?.id || !fileRecord?.formats || typeof fileRecord.formats !== "object") {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const providerService = strapi.plugin("upload")?.service?.("provider");
|
|
460
|
+
const nextFormats = {};
|
|
461
|
+
const removedFormats = [];
|
|
462
|
+
for (const [k, fmt] of Object.entries(fileRecord.formats)) {
|
|
463
|
+
if (k.startsWith("ci_")) {
|
|
464
|
+
removedFormats.push(fmt);
|
|
465
|
+
} else {
|
|
466
|
+
nextFormats[k] = fmt;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
if (removedFormats.length === 0) return;
|
|
470
|
+
if (providerService && typeof providerService.delete === "function") {
|
|
471
|
+
for (const fmt of removedFormats) {
|
|
472
|
+
try {
|
|
473
|
+
await providerService.delete(fmt);
|
|
474
|
+
} catch {
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
await strapi.db.query("plugin::upload.file").update({
|
|
479
|
+
where: { id: fileRecord.id },
|
|
480
|
+
data: { formats: nextFormats }
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
async function enrichMediaAssetNode(strapi, asset, opts = {}) {
|
|
484
|
+
if (!asset) return asset;
|
|
485
|
+
const isStringInput = typeof asset === "string";
|
|
486
|
+
const rawUrl = isStringInput ? asset : asset.original_url || asset.url || asset.target_url || asset.src || "";
|
|
487
|
+
if (!rawUrl || typeof rawUrl !== "string") return asset;
|
|
488
|
+
const fileRecord = await findUploadFileForAsset(strapi, asset, opts.fileCache);
|
|
489
|
+
if (!fileRecord) {
|
|
490
|
+
return asset;
|
|
491
|
+
}
|
|
492
|
+
const canonicalMasterUrl = fileRecord.url || rawUrl;
|
|
493
|
+
if (!isOptimizableRasterImage(fileRecord.mime, fileRecord.ext || canonicalMasterUrl)) {
|
|
494
|
+
if (isStringInput) return canonicalMasterUrl;
|
|
495
|
+
return {
|
|
496
|
+
...asset,
|
|
497
|
+
id: fileRecord.id,
|
|
498
|
+
hash: fileRecord.hash,
|
|
499
|
+
original_url: canonicalMasterUrl,
|
|
500
|
+
url: canonicalMasterUrl,
|
|
501
|
+
target_url: canonicalMasterUrl
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
const spec = normalizeImageProcessSpec(
|
|
505
|
+
opts.imageSettings,
|
|
506
|
+
opts.defaultAutoMaxW || 1920
|
|
507
|
+
);
|
|
508
|
+
let latestFile = fileRecord;
|
|
509
|
+
let activeVariantUrl;
|
|
510
|
+
if (spec.processMode !== "none") {
|
|
511
|
+
try {
|
|
512
|
+
const primary = await ensureMediaVariant(strapi, latestFile, {
|
|
513
|
+
processMode: spec.processMode,
|
|
514
|
+
w: spec.w,
|
|
515
|
+
h: spec.h,
|
|
516
|
+
q: spec.q,
|
|
517
|
+
rotate: spec.rotate
|
|
518
|
+
});
|
|
519
|
+
latestFile = primary.updatedFile || latestFile;
|
|
520
|
+
if (primary.formatEntry?.url) {
|
|
521
|
+
activeVariantUrl = primary.formatEntry.url;
|
|
522
|
+
}
|
|
523
|
+
} catch (err) {
|
|
524
|
+
strapi.log?.warn?.(
|
|
525
|
+
`[content-input] Image variant generation skipped for "${canonicalMasterUrl}": ${err?.message || err}`
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (opts.alsoEnsureAutoMaxW && opts.alsoEnsureAutoMaxW > 0 && spec.processMode !== "none" && !(spec.processMode === "auto" && spec.w === opts.alsoEnsureAutoMaxW)) {
|
|
530
|
+
try {
|
|
531
|
+
const secondary = await ensureMediaVariant(strapi, latestFile, {
|
|
532
|
+
processMode: "auto",
|
|
533
|
+
w: opts.alsoEnsureAutoMaxW,
|
|
534
|
+
h: 0,
|
|
535
|
+
q: spec.q
|
|
536
|
+
});
|
|
537
|
+
latestFile = secondary.updatedFile || latestFile;
|
|
538
|
+
} catch {
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if (opts.fileCache && latestFile?.id) {
|
|
542
|
+
opts.fileCache.set(`id:${latestFile.id}`, latestFile);
|
|
543
|
+
if (latestFile.hash) opts.fileCache.set(`hash:${latestFile.hash}`, latestFile);
|
|
544
|
+
if (latestFile.url) opts.fileCache.set(`url:${String(latestFile.url).split("?")[0]}`, latestFile);
|
|
545
|
+
}
|
|
546
|
+
const compactFormats = compactAssetFormats(latestFile.formats);
|
|
547
|
+
if (isStringInput) {
|
|
548
|
+
return activeVariantUrl || canonicalMasterUrl;
|
|
549
|
+
}
|
|
550
|
+
const nextAsset = {
|
|
551
|
+
...asset,
|
|
552
|
+
id: latestFile.id,
|
|
553
|
+
hash: latestFile.hash,
|
|
554
|
+
original_url: canonicalMasterUrl,
|
|
555
|
+
url: canonicalMasterUrl,
|
|
556
|
+
target_url: canonicalMasterUrl,
|
|
557
|
+
filename: asset.filename || asset.name || latestFile.name || "image",
|
|
558
|
+
mime_type: asset.mime_type || latestFile.mime || "image/webp",
|
|
559
|
+
width: asset.width || latestFile.width || void 0,
|
|
560
|
+
height: asset.height || latestFile.height || void 0
|
|
561
|
+
};
|
|
562
|
+
if (spec.processMode === "none") {
|
|
563
|
+
delete nextAsset.optimized_url;
|
|
564
|
+
} else if (activeVariantUrl) {
|
|
565
|
+
nextAsset.optimized_url = activeVariantUrl;
|
|
566
|
+
}
|
|
567
|
+
if (compactFormats) {
|
|
568
|
+
nextAsset.formats = compactFormats;
|
|
569
|
+
}
|
|
570
|
+
return nextAsset;
|
|
571
|
+
}
|
|
572
|
+
async function runWithConcurrency(tasks, concurrency = 3) {
|
|
573
|
+
const results = new Array(tasks.length);
|
|
574
|
+
let cursor = 0;
|
|
575
|
+
async function worker() {
|
|
576
|
+
while (cursor < tasks.length) {
|
|
577
|
+
const idx = cursor++;
|
|
578
|
+
results[idx] = await tasks[idx]();
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const poolSize = Math.min(Math.max(1, concurrency), tasks.length);
|
|
582
|
+
await Promise.all(Array.from({ length: poolSize }, () => worker()));
|
|
583
|
+
return results;
|
|
584
|
+
}
|
|
585
|
+
async function optimizeHtmlImgSources(strapi, html, fileCache) {
|
|
586
|
+
if (!html || typeof html !== "string" || !html.includes("<img")) return html;
|
|
587
|
+
const imgRegex = /(<img\b[^>]*?\bsrc=(["']))([^"']+)(\2[^>]*>)/gi;
|
|
588
|
+
const matches = Array.from(html.matchAll(imgRegex));
|
|
589
|
+
if (matches.length === 0) return html;
|
|
590
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
591
|
+
const uniqueSrcs = Array.from(new Set(matches.map((m) => m[3]).filter(Boolean)));
|
|
592
|
+
await runWithConcurrency(
|
|
593
|
+
uniqueSrcs.map((srcUrl) => async () => {
|
|
594
|
+
if (!isOptimizableRasterImage(void 0, srcUrl)) return;
|
|
595
|
+
const fileRecord = await findUploadFileForAsset(strapi, srcUrl, fileCache);
|
|
596
|
+
if (!fileRecord) return;
|
|
597
|
+
if (!isOptimizableRasterImage(fileRecord.mime, fileRecord.ext || fileRecord.url)) return;
|
|
598
|
+
try {
|
|
599
|
+
const res = await ensureMediaVariant(strapi, fileRecord, {
|
|
600
|
+
processMode: "auto",
|
|
601
|
+
w: 1600,
|
|
602
|
+
h: 0
|
|
603
|
+
});
|
|
604
|
+
if (res.formatEntry?.url) {
|
|
605
|
+
replacements.set(srcUrl, res.formatEntry.url);
|
|
606
|
+
}
|
|
607
|
+
} catch {
|
|
608
|
+
}
|
|
609
|
+
}),
|
|
610
|
+
3
|
|
611
|
+
);
|
|
612
|
+
if (replacements.size === 0) return html;
|
|
613
|
+
return html.replace(imgRegex, (full, prefix, _quote, srcVal, suffix) => {
|
|
614
|
+
const nextUrl = replacements.get(srcVal);
|
|
615
|
+
return nextUrl ? `${prefix}${nextUrl}${suffix}` : full;
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
async function syncContentInputTreeMedia(strapi, rawValue) {
|
|
619
|
+
if (!rawValue) return rawValue;
|
|
620
|
+
const wasString = typeof rawValue === "string";
|
|
621
|
+
let parsed = rawValue;
|
|
622
|
+
if (wasString) {
|
|
623
|
+
const trimmed = rawValue.trim();
|
|
624
|
+
if (!trimmed) return rawValue;
|
|
625
|
+
try {
|
|
626
|
+
parsed = JSON.parse(trimmed);
|
|
627
|
+
} catch {
|
|
628
|
+
return rawValue;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
if (!Array.isArray(parsed)) {
|
|
632
|
+
return rawValue;
|
|
633
|
+
}
|
|
634
|
+
const rows = JSON.parse(JSON.stringify(parsed));
|
|
635
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
636
|
+
const jobs = [];
|
|
637
|
+
const scheduleAsset = (holder, key, opts) => {
|
|
638
|
+
const current = holder?.[key];
|
|
639
|
+
if (!current) return;
|
|
640
|
+
jobs.push(async () => {
|
|
641
|
+
holder[key] = await enrichMediaAssetNode(strapi, current, {
|
|
642
|
+
...opts,
|
|
643
|
+
fileCache
|
|
644
|
+
});
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
const scheduleHtml = (holder, key) => {
|
|
648
|
+
const val = holder?.[key];
|
|
649
|
+
if (typeof val !== "string" || !val.includes("<img")) return;
|
|
650
|
+
jobs.push(async () => {
|
|
651
|
+
holder[key] = await optimizeHtmlImgSources(strapi, val, fileCache);
|
|
652
|
+
});
|
|
653
|
+
};
|
|
654
|
+
const walkRows = (rowList) => {
|
|
655
|
+
if (!Array.isArray(rowList)) return;
|
|
656
|
+
for (const row of rowList) {
|
|
657
|
+
if (!row || typeof row !== "object") continue;
|
|
658
|
+
if (row.bgImage) {
|
|
659
|
+
scheduleAsset(row, "bgImage", {
|
|
660
|
+
imageSettings: row.bgOptions?.imageSettings,
|
|
661
|
+
defaultAutoMaxW: 1920
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
const blocks = Array.isArray(row.blocks) ? row.blocks : [];
|
|
665
|
+
for (const block of blocks) {
|
|
666
|
+
if (!block || typeof block !== "object") continue;
|
|
667
|
+
if (block.bgImage) {
|
|
668
|
+
scheduleAsset(block, "bgImage", {
|
|
669
|
+
imageSettings: block.bgOptions?.imageSettings,
|
|
670
|
+
defaultAutoMaxW: 1920
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
const widgets = Array.isArray(block.widgets) ? block.widgets : [];
|
|
674
|
+
for (const widget of widgets) {
|
|
675
|
+
if (!widget || typeof widget !== "object") continue;
|
|
676
|
+
const wId = widget.id;
|
|
677
|
+
const wOpts = widget.options || {};
|
|
678
|
+
const wData = widget.data;
|
|
679
|
+
if (wId === "gallery") {
|
|
680
|
+
const list = Array.isArray(wData) ? wData : Array.isArray(wData?.images) ? wData.images : null;
|
|
681
|
+
if (list) {
|
|
682
|
+
const popupEnabled = wOpts.popup !== false;
|
|
683
|
+
for (let i = 0; i < list.length; i++) {
|
|
684
|
+
scheduleAsset(list, i, {
|
|
685
|
+
imageSettings: wOpts.imageSettings,
|
|
686
|
+
defaultAutoMaxW: 1600,
|
|
687
|
+
alsoEnsureAutoMaxW: popupEnabled ? 1920 : 0
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
} else if (wId === "singleImage" && wData && typeof wData === "object") {
|
|
692
|
+
if (wData.image) {
|
|
693
|
+
scheduleAsset(wData, "image", {
|
|
694
|
+
imageSettings: wOpts.imageSettings || wData.imageSettings,
|
|
695
|
+
defaultAutoMaxW: 1920
|
|
696
|
+
});
|
|
697
|
+
} else if (wData.url || wData.target_url) {
|
|
698
|
+
scheduleAsset(widget, "data", {
|
|
699
|
+
imageSettings: wOpts.imageSettings,
|
|
700
|
+
defaultAutoMaxW: 1920
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
} else if (wId === "banner" && wData && typeof wData === "object") {
|
|
704
|
+
if (wData.image) {
|
|
705
|
+
scheduleAsset(wData, "image", {
|
|
706
|
+
imageSettings: wOpts.imageSettings || wData.imageSettings,
|
|
707
|
+
defaultAutoMaxW: 1920
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
} else if (wId === "youtubeVideo") {
|
|
711
|
+
if (wOpts.thumbnailImage) {
|
|
712
|
+
scheduleAsset(wOpts, "thumbnailImage", {
|
|
713
|
+
imageSettings: wOpts.imageSettings,
|
|
714
|
+
defaultAutoMaxW: 1280
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
if (Array.isArray(wData)) {
|
|
718
|
+
for (const vid of wData) {
|
|
719
|
+
if (vid && typeof vid === "object" && vid.customThumbnail) {
|
|
720
|
+
scheduleAsset(vid, "customThumbnail", {
|
|
721
|
+
imageSettings: wOpts.imageSettings,
|
|
722
|
+
defaultAutoMaxW: 1280
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
} else if (wData && typeof wData === "object" && wData.customThumbnail) {
|
|
727
|
+
scheduleAsset(wData, "customThumbnail", {
|
|
728
|
+
imageSettings: wOpts.imageSettings,
|
|
729
|
+
defaultAutoMaxW: 1280
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
} else if (wId === "heroSlider" && wData && typeof wData === "object") {
|
|
733
|
+
const globalHeroImgSettings = wData.settings?.imageSettings || wOpts.imageSettings;
|
|
734
|
+
const slides = Array.isArray(wData.slides) ? wData.slides : [];
|
|
735
|
+
for (const slide of slides) {
|
|
736
|
+
if (!slide || typeof slide !== "object") continue;
|
|
737
|
+
if (slide.bgImage) {
|
|
738
|
+
scheduleAsset(slide, "bgImage", {
|
|
739
|
+
imageSettings: slide.imageSettings || globalHeroImgSettings,
|
|
740
|
+
defaultAutoMaxW: 1920
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
if (slide.mobileBgImage) {
|
|
744
|
+
scheduleAsset(slide, "mobileBgImage", {
|
|
745
|
+
imageSettings: slide.mobileImageSettings,
|
|
746
|
+
defaultAutoMaxW: 1080
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
const layers = Array.isArray(slide.layers) ? slide.layers : [];
|
|
750
|
+
for (const layer of layers) {
|
|
751
|
+
if (layer && typeof layer === "object" && layer.image) {
|
|
752
|
+
scheduleAsset(layer, "image", {
|
|
753
|
+
imageSettings: layer.imageSettings,
|
|
754
|
+
defaultAutoMaxW: 1200
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
} else if (wId === "customCard" && wData && typeof wData === "object") {
|
|
760
|
+
const cardImgSettings = wData.design?.imageSettings || wOpts.imageSettings;
|
|
761
|
+
const cards = Array.isArray(wData.cards) ? wData.cards : [];
|
|
762
|
+
for (const card of cards) {
|
|
763
|
+
if (!card || typeof card !== "object") continue;
|
|
764
|
+
if (card.image) {
|
|
765
|
+
scheduleAsset(card, "image", {
|
|
766
|
+
imageSettings: cardImgSettings,
|
|
767
|
+
defaultAutoMaxW: 960
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
if (card.authorAvatar) {
|
|
771
|
+
scheduleAsset(card, "authorAvatar", {
|
|
772
|
+
imageSettings: { process: "fit", cWidth: 240, cHeight: 240 },
|
|
773
|
+
defaultAutoMaxW: 240
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
} else if (wId === "entityCard" && wData && typeof wData === "object") {
|
|
778
|
+
const ecImgSettings = wOpts.imageSettings || wOpts.cardProps?.imageSettings;
|
|
779
|
+
if (wData.overrides?.image) {
|
|
780
|
+
scheduleAsset(wData.overrides, "image", {
|
|
781
|
+
imageSettings: ecImgSettings,
|
|
782
|
+
defaultAutoMaxW: 960
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
if (wData.entity?.image) {
|
|
786
|
+
scheduleAsset(wData.entity, "image", {
|
|
787
|
+
imageSettings: ecImgSettings,
|
|
788
|
+
defaultAutoMaxW: 960
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
if (Array.isArray(wData.items)) {
|
|
792
|
+
for (const item of wData.items) {
|
|
793
|
+
if (!item || typeof item !== "object") continue;
|
|
794
|
+
if (item.overrides?.image) {
|
|
795
|
+
scheduleAsset(item.overrides, "image", {
|
|
796
|
+
imageSettings: ecImgSettings,
|
|
797
|
+
defaultAutoMaxW: 960
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
if (item.entity?.image) {
|
|
801
|
+
scheduleAsset(item.entity, "image", {
|
|
802
|
+
imageSettings: ecImgSettings,
|
|
803
|
+
defaultAutoMaxW: 960
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
} else if (wId === "HtmlEditor") {
|
|
809
|
+
if (typeof wData === "string") {
|
|
810
|
+
scheduleHtml(widget, "data");
|
|
811
|
+
} else if (wData && typeof wData === "object" && typeof wData.content === "string") {
|
|
812
|
+
scheduleHtml(wData, "content");
|
|
813
|
+
}
|
|
814
|
+
} else if (wId === "tab" || wId === "accordion") {
|
|
815
|
+
const nodes = Array.isArray(wData) ? wData : Array.isArray(wData?.nodes) ? wData.nodes : Array.isArray(wData?.tabs) ? wData.tabs : [];
|
|
816
|
+
for (const node of nodes) {
|
|
817
|
+
if (!node || typeof node !== "object") continue;
|
|
818
|
+
if (Array.isArray(node.rows)) walkRows(node.rows);
|
|
819
|
+
if (Array.isArray(node.content)) walkRows(node.content);
|
|
820
|
+
if (Array.isArray(node.content?.data)) walkRows(node.content.data);
|
|
821
|
+
if (typeof node.html === "string") scheduleHtml(node, "html");
|
|
822
|
+
if (typeof node.content === "string") scheduleHtml(node, "content");
|
|
823
|
+
if (typeof node.content?.html === "string") scheduleHtml(node.content, "html");
|
|
824
|
+
}
|
|
825
|
+
} else if (wId === "survey" && wData && typeof wData === "object") {
|
|
826
|
+
const qLists = [wData.questions, wData.survey?.questions].filter(Array.isArray);
|
|
827
|
+
for (const qList of qLists) {
|
|
828
|
+
for (const q of qList) {
|
|
829
|
+
if (!q || typeof q !== "object" || !Array.isArray(q.options)) continue;
|
|
830
|
+
for (const opt of q.options) {
|
|
831
|
+
if (opt && typeof opt === "object" && opt.image) {
|
|
832
|
+
scheduleAsset(opt, "image", {
|
|
833
|
+
defaultAutoMaxW: 800
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
} else if (wId === "dataTable" && wData && typeof wData === "object") {
|
|
840
|
+
const cols = Array.isArray(wData.columns) ? wData.columns : [];
|
|
841
|
+
const imageColKeys = cols.filter((c) => c && c.type === "image" && c.key).map((c) => String(c.key));
|
|
842
|
+
const dtRows = Array.isArray(wData.rows) ? wData.rows : [];
|
|
843
|
+
if (imageColKeys.length > 0 && dtRows.length > 0) {
|
|
844
|
+
for (const dtRow of dtRows) {
|
|
845
|
+
if (!dtRow || typeof dtRow !== "object") continue;
|
|
846
|
+
for (const key of imageColKeys) {
|
|
847
|
+
if (dtRow[key]) {
|
|
848
|
+
scheduleAsset(dtRow, key, {
|
|
849
|
+
defaultAutoMaxW: 800
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
walkRows(rows);
|
|
861
|
+
if (jobs.length > 0) {
|
|
862
|
+
await runWithConcurrency(jobs, 3);
|
|
863
|
+
}
|
|
864
|
+
return wasString ? JSON.stringify(rows) : rows;
|
|
865
|
+
}
|
|
866
|
+
async function syncSurveyQuestionsMedia(strapi, questions) {
|
|
867
|
+
if (!Array.isArray(questions) || questions.length === 0) return questions;
|
|
868
|
+
const cloned = JSON.parse(JSON.stringify(questions));
|
|
869
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
870
|
+
const jobs = [];
|
|
871
|
+
for (const q of cloned) {
|
|
872
|
+
if (!q || typeof q !== "object" || !Array.isArray(q.options)) continue;
|
|
873
|
+
for (const opt of q.options) {
|
|
874
|
+
if (opt && typeof opt === "object" && opt.image) {
|
|
875
|
+
jobs.push(async () => {
|
|
876
|
+
opt.image = await enrichMediaAssetNode(strapi, opt.image, {
|
|
877
|
+
defaultAutoMaxW: 800,
|
|
878
|
+
fileCache
|
|
879
|
+
});
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
if (jobs.length > 0) {
|
|
885
|
+
await runWithConcurrency(jobs, 3);
|
|
886
|
+
}
|
|
887
|
+
return cloned;
|
|
888
|
+
}
|
|
889
|
+
function collectContentInputModelFields(strapi) {
|
|
890
|
+
const map = /* @__PURE__ */ new Map();
|
|
891
|
+
const inspectSchemas = (schemas) => {
|
|
892
|
+
if (!schemas || typeof schemas !== "object") return;
|
|
893
|
+
for (const [uid, schema] of Object.entries(schemas)) {
|
|
894
|
+
const attrs = schema?.attributes;
|
|
895
|
+
if (!attrs || typeof attrs !== "object") continue;
|
|
896
|
+
const matchingFields = [];
|
|
897
|
+
for (const [fieldName, attrDef] of Object.entries(attrs)) {
|
|
898
|
+
if (attrDef?.customField === "plugin::content-input.content-input") {
|
|
899
|
+
matchingFields.push(fieldName);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
if (matchingFields.length > 0) {
|
|
903
|
+
map.set(uid, matchingFields);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
inspectSchemas(strapi.contentTypes);
|
|
908
|
+
inspectSchemas(strapi.components);
|
|
909
|
+
return map;
|
|
910
|
+
}
|
|
24
911
|
const bootstrap = async ({ strapi }) => {
|
|
25
912
|
try {
|
|
913
|
+
await strapi.plugin("content-input").service("ci-color").ensureSeeded();
|
|
26
914
|
await strapi.plugin("content-input").service("ci-form").ensureSeeded();
|
|
27
915
|
await strapi.plugin("content-input").service("ci-survey").ensureSeeded(false);
|
|
28
916
|
} catch (err) {
|
|
29
917
|
strapi.log.warn(`[content-input] Bootstrap seed skipped: ${err?.message || err}`);
|
|
30
918
|
}
|
|
919
|
+
try {
|
|
920
|
+
const modelFieldMap = collectContentInputModelFields(strapi);
|
|
921
|
+
const surveyUid = "plugin::content-input.ci-survey";
|
|
922
|
+
const subscribedModels = Array.from(/* @__PURE__ */ new Set([...modelFieldMap.keys(), surveyUid]));
|
|
923
|
+
if (subscribedModels.length > 0 && strapi.db?.lifecycles?.subscribe) {
|
|
924
|
+
const processEventData = async (event) => {
|
|
925
|
+
const uid = event?.model?.uid;
|
|
926
|
+
const data = event?.params?.data;
|
|
927
|
+
if (!uid || !data || typeof data !== "object") return;
|
|
928
|
+
if (uid === surveyUid) {
|
|
929
|
+
if (Array.isArray(data.questions) && data.questions.length > 0) {
|
|
930
|
+
try {
|
|
931
|
+
data.questions = await syncSurveyQuestionsMedia(strapi, data.questions);
|
|
932
|
+
} catch (err) {
|
|
933
|
+
strapi.log.warn(
|
|
934
|
+
`[content-input] Survey media optimization warning: ${err?.message || err}`
|
|
935
|
+
);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
const fields = modelFieldMap.get(uid);
|
|
941
|
+
if (!fields || fields.length === 0) return;
|
|
942
|
+
for (const fieldName of fields) {
|
|
943
|
+
if (data[fieldName] !== void 0 && data[fieldName] !== null) {
|
|
944
|
+
try {
|
|
945
|
+
data[fieldName] = await syncContentInputTreeMedia(strapi, data[fieldName]);
|
|
946
|
+
} catch (err) {
|
|
947
|
+
strapi.log.warn(
|
|
948
|
+
`[content-input] Media sync warning on ${uid}.${fieldName}: ${err?.message || err}`
|
|
949
|
+
);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
strapi.db.lifecycles.subscribe({
|
|
955
|
+
models: subscribedModels,
|
|
956
|
+
async beforeCreate(event) {
|
|
957
|
+
await processEventData(event);
|
|
958
|
+
},
|
|
959
|
+
async beforeUpdate(event) {
|
|
960
|
+
await processEventData(event);
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
} catch (err) {
|
|
965
|
+
strapi.log.warn(
|
|
966
|
+
`[content-input] Lifecycle registration skipped: ${err?.message || err}`
|
|
967
|
+
);
|
|
968
|
+
}
|
|
31
969
|
};
|
|
32
970
|
const destroy = ({ strapi }) => {
|
|
33
971
|
};
|
|
34
972
|
const config = {
|
|
35
973
|
default: {
|
|
36
|
-
previewUrl: "/ci-preview"
|
|
974
|
+
previewUrl: "/ci-preview",
|
|
975
|
+
imageVariantFolder: process.env.CI_IMAGE_VARIANT_FOLDER || "ci-optimized",
|
|
976
|
+
imageVariantFormat: process.env.CI_IMAGE_VARIANT_FORMAT || "webp",
|
|
977
|
+
imageVariantQuality: 85,
|
|
978
|
+
redirectProxyToCdn: true
|
|
37
979
|
},
|
|
38
980
|
validator() {
|
|
39
981
|
}
|
|
40
982
|
};
|
|
983
|
+
const kind$6 = "collectionType";
|
|
984
|
+
const collectionName$6 = "ci_templates";
|
|
985
|
+
const info$6 = { "singularName": "ci-template", "pluralName": "ci-templates", "displayName": "ContentInput Template", "description": "Saved visual editor row/section templates" };
|
|
986
|
+
const options$6 = { "draftAndPublish": false };
|
|
987
|
+
const pluginOptions$6 = { "content-manager": { "visible": false }, "content-type-builder": { "visible": false } };
|
|
988
|
+
const attributes$6 = { "name": { "type": "string", "required": true }, "category": { "type": "string", "default": "custom" }, "structure": { "type": "json", "required": true }, "thumbnail": { "type": "string", "default": "" } };
|
|
989
|
+
const templateSchema = {
|
|
990
|
+
kind: kind$6,
|
|
991
|
+
collectionName: collectionName$6,
|
|
992
|
+
info: info$6,
|
|
993
|
+
options: options$6,
|
|
994
|
+
pluginOptions: pluginOptions$6,
|
|
995
|
+
attributes: attributes$6
|
|
996
|
+
};
|
|
41
997
|
const kind$5 = "collectionType";
|
|
42
|
-
const collectionName$5 = "
|
|
43
|
-
const info$5 = { "singularName": "ci-
|
|
998
|
+
const collectionName$5 = "ci_menus";
|
|
999
|
+
const info$5 = { "singularName": "ci-menu", "pluralName": "ci-menus", "displayName": "ContentInput Menu", "description": "Reusable nested menus (horizontal & vertical) for ContentInput" };
|
|
44
1000
|
const options$5 = { "draftAndPublish": false };
|
|
45
1001
|
const pluginOptions$5 = { "content-manager": { "visible": false }, "content-type-builder": { "visible": false } };
|
|
46
|
-
const attributes$5 = { "name": { "type": "string", "required": true }, "
|
|
47
|
-
const
|
|
1002
|
+
const attributes$5 = { "name": { "type": "string", "required": true }, "slug": { "type": "string", "required": true }, "mode": { "type": "string", "default": "horizontal" }, "items": { "type": "json", "required": true }, "options": { "type": "json" } };
|
|
1003
|
+
const menuSchema = {
|
|
48
1004
|
kind: kind$5,
|
|
49
1005
|
collectionName: collectionName$5,
|
|
50
1006
|
info: info$5,
|
|
@@ -53,12 +1009,12 @@ const templateSchema = {
|
|
|
53
1009
|
attributes: attributes$5
|
|
54
1010
|
};
|
|
55
1011
|
const kind$4 = "collectionType";
|
|
56
|
-
const collectionName$4 = "
|
|
57
|
-
const info$4 = { "singularName": "ci-
|
|
1012
|
+
const collectionName$4 = "ci_forms";
|
|
1013
|
+
const info$4 = { "singularName": "ci-form", "pluralName": "ci-forms", "displayName": "ContentInput Dynamic Form", "description": "Reusable cms-core style dynamic forms with responsive grid layout, validation rules, reCAPTCHA and mail delivery settings" };
|
|
58
1014
|
const options$4 = { "draftAndPublish": false };
|
|
59
|
-
const pluginOptions$4 = { "content-manager": { "visible":
|
|
60
|
-
const attributes$4 = { "
|
|
61
|
-
const
|
|
1015
|
+
const pluginOptions$4 = { "content-manager": { "visible": true }, "content-type-builder": { "visible": false } };
|
|
1016
|
+
const attributes$4 = { "title": { "type": "string", "required": true }, "slug": { "type": "string", "required": true }, "to": { "type": "string" }, "subject": { "type": "string" }, "buttonLabel": { "type": "json" }, "successMessage": { "type": "json" }, "redirect": { "type": "string" }, "hideLabels": { "type": "boolean", "default": false }, "useRecaptcha": { "type": "boolean", "default": true }, "recaptchaSiteKey": { "type": "string" }, "recaptchaSecretKey": { "type": "string", "private": true }, "mailConfig": { "type": "json", "private": true }, "fields": { "type": "json", "required": true }, "form": { "type": "json", "required": true } };
|
|
1017
|
+
const formSchema = {
|
|
62
1018
|
kind: kind$4,
|
|
63
1019
|
collectionName: collectionName$4,
|
|
64
1020
|
info: info$4,
|
|
@@ -67,12 +1023,12 @@ const menuSchema = {
|
|
|
67
1023
|
attributes: attributes$4
|
|
68
1024
|
};
|
|
69
1025
|
const kind$3 = "collectionType";
|
|
70
|
-
const collectionName$3 = "
|
|
71
|
-
const info$3 = { "singularName": "ci-form", "pluralName": "ci-
|
|
1026
|
+
const collectionName$3 = "ci_form_submissions";
|
|
1027
|
+
const info$3 = { "singularName": "ci-form-submission", "pluralName": "ci-form-submissions", "displayName": "ContentInput Form Submission", "description": "Submitted entries from ContentInput dynamic forms" };
|
|
72
1028
|
const options$3 = { "draftAndPublish": false };
|
|
73
1029
|
const pluginOptions$3 = { "content-manager": { "visible": true }, "content-type-builder": { "visible": false } };
|
|
74
|
-
const attributes$3 = { "
|
|
75
|
-
const
|
|
1030
|
+
const attributes$3 = { "formId": { "type": "string", "required": true }, "formSlug": { "type": "string" }, "formTitle": { "type": "string" }, "data": { "type": "json", "required": true }, "ip": { "type": "string" }, "userAgent": { "type": "string" }, "mailSent": { "type": "boolean", "default": false }, "mailInfo": { "type": "json" } };
|
|
1031
|
+
const formSubmissionSchema = {
|
|
76
1032
|
kind: kind$3,
|
|
77
1033
|
collectionName: collectionName$3,
|
|
78
1034
|
info: info$3,
|
|
@@ -81,12 +1037,12 @@ const formSchema = {
|
|
|
81
1037
|
attributes: attributes$3
|
|
82
1038
|
};
|
|
83
1039
|
const kind$2 = "collectionType";
|
|
84
|
-
const collectionName$2 = "
|
|
85
|
-
const info$2 = { "singularName": "ci-
|
|
1040
|
+
const collectionName$2 = "ci_surveys";
|
|
1041
|
+
const info$2 = { "singularName": "ci-survey", "pluralName": "ci-surveys", "displayName": "ContentInput Survey", "description": "Enterprise surveys, multi-step questionnaires, and live polls with i18n, conditional logic, and analytics" };
|
|
86
1042
|
const options$2 = { "draftAndPublish": false };
|
|
87
1043
|
const pluginOptions$2 = { "content-manager": { "visible": true }, "content-type-builder": { "visible": false } };
|
|
88
|
-
const attributes$2 = { "
|
|
89
|
-
const
|
|
1044
|
+
const attributes$2 = { "title": { "type": "string", "required": true }, "titleI18n": { "type": "json" }, "slug": { "type": "string", "required": true }, "description": { "type": "json" }, "status": { "type": "enumeration", "enum": ["draft", "published", "closed"], "default": "published" }, "displayMode": { "type": "enumeration", "enum": ["quick_poll", "single_page", "multi_step"], "default": "single_page" }, "startsAt": { "type": "datetime" }, "endsAt": { "type": "datetime" }, "quotaLimit": { "type": "integer" }, "submissionPolicy": { "type": "enumeration", "enum": ["unlimited", "one_per_voter", "one_per_token"], "default": "one_per_voter" }, "anonymizeIp": { "type": "boolean", "default": true }, "showPublicResults": { "type": "enumeration", "enum": ["never", "after_vote", "always"], "default": "never" }, "allowBackNavigation": { "type": "boolean", "default": true }, "showProgressBar": { "type": "boolean", "default": true }, "useRecaptcha": { "type": "boolean", "default": false }, "recaptchaSiteKey": { "type": "string" }, "recaptchaSecretKey": { "type": "string", "private": true }, "mailConfig": { "type": "json", "private": true }, "steps": { "type": "json" }, "questions": { "type": "json", "required": true }, "settings": { "type": "json" }, "version": { "type": "integer", "default": 1 } };
|
|
1045
|
+
const surveySchema = {
|
|
90
1046
|
kind: kind$2,
|
|
91
1047
|
collectionName: collectionName$2,
|
|
92
1048
|
info: info$2,
|
|
@@ -95,12 +1051,12 @@ const formSubmissionSchema = {
|
|
|
95
1051
|
attributes: attributes$2
|
|
96
1052
|
};
|
|
97
1053
|
const kind$1 = "collectionType";
|
|
98
|
-
const collectionName$1 = "
|
|
99
|
-
const info$1 = { "singularName": "ci-survey", "pluralName": "ci-
|
|
1054
|
+
const collectionName$1 = "ci_survey_responses";
|
|
1055
|
+
const info$1 = { "singularName": "ci-survey-response", "pluralName": "ci-survey-responses", "displayName": "ContentInput Survey Response", "description": "Recorded participant responses and telemetry for ContentInput surveys and polls" };
|
|
100
1056
|
const options$1 = { "draftAndPublish": false };
|
|
101
1057
|
const pluginOptions$1 = { "content-manager": { "visible": true }, "content-type-builder": { "visible": false } };
|
|
102
|
-
const attributes$1 = { "
|
|
103
|
-
const
|
|
1058
|
+
const attributes$1 = { "surveyId": { "type": "string", "required": true }, "surveySlug": { "type": "string", "required": true }, "surveyTitle": { "type": "string" }, "surveyVersion": { "type": "integer", "default": 1 }, "answers": { "type": "json", "required": true }, "otherTexts": { "type": "json" }, "score": { "type": "float" }, "npsValue": { "type": "integer" }, "npsCategory": { "type": "string" }, "locale": { "type": "string", "default": "tr" }, "durationSeconds": { "type": "integer", "default": 0 }, "voterHash": { "type": "string" }, "respondentToken": { "type": "string" }, "ip": { "type": "string" }, "userAgent": { "type": "string" }, "submittedAt": { "type": "datetime" } };
|
|
1059
|
+
const surveyResponseSchema = {
|
|
104
1060
|
kind: kind$1,
|
|
105
1061
|
collectionName: collectionName$1,
|
|
106
1062
|
info: info$1,
|
|
@@ -109,12 +1065,12 @@ const surveySchema = {
|
|
|
109
1065
|
attributes: attributes$1
|
|
110
1066
|
};
|
|
111
1067
|
const kind = "collectionType";
|
|
112
|
-
const collectionName = "
|
|
113
|
-
const info = { "singularName": "ci-
|
|
1068
|
+
const collectionName = "ci_color_palettes";
|
|
1069
|
+
const info = { "singularName": "ci-color-palette", "pluralName": "ci-color-palettes", "displayName": "ContentInput Color Palette", "description": "Theme color codes (HEX & RGB/RGBA semantic tokens + custom brand color tokens)" };
|
|
114
1070
|
const options = { "draftAndPublish": false };
|
|
115
|
-
const pluginOptions = { "content-manager": { "visible":
|
|
116
|
-
const attributes = { "
|
|
117
|
-
const
|
|
1071
|
+
const pluginOptions = { "content-manager": { "visible": false }, "content-type-builder": { "visible": false } };
|
|
1072
|
+
const attributes = { "name": { "type": "string", "required": true }, "slug": { "type": "string", "required": true, "unique": true }, "description": { "type": "string", "default": "" }, "isActive": { "type": "boolean", "default": false }, "semanticTokens": { "type": "json", "required": true }, "customTokens": { "type": "json", "default": [] } };
|
|
1073
|
+
const colorPaletteSchema = {
|
|
118
1074
|
kind,
|
|
119
1075
|
collectionName,
|
|
120
1076
|
info,
|
|
@@ -140,6 +1096,9 @@ const contentTypes = {
|
|
|
140
1096
|
},
|
|
141
1097
|
"ci-survey-response": {
|
|
142
1098
|
schema: surveyResponseSchema
|
|
1099
|
+
},
|
|
1100
|
+
"ci-color-palette": {
|
|
1101
|
+
schema: colorPaletteSchema
|
|
143
1102
|
}
|
|
144
1103
|
};
|
|
145
1104
|
const ciTemplateController = ({ strapi }) => ({
|
|
@@ -153,7 +1112,11 @@ const ciTemplateController = ({ strapi }) => ({
|
|
|
153
1112
|
},
|
|
154
1113
|
async save(ctx) {
|
|
155
1114
|
try {
|
|
156
|
-
const
|
|
1115
|
+
const body = ctx.request.body || {};
|
|
1116
|
+
const name = body.name;
|
|
1117
|
+
const structure = body.structure ?? body.rows;
|
|
1118
|
+
const category = body.category;
|
|
1119
|
+
const thumbnail = body.thumbnail;
|
|
157
1120
|
if (!name || !structure) {
|
|
158
1121
|
return ctx.badRequest("Name and structure are required");
|
|
159
1122
|
}
|
|
@@ -263,10 +1226,6 @@ const ciMenuController = ({ strapi }) => ({
|
|
|
263
1226
|
}
|
|
264
1227
|
}
|
|
265
1228
|
});
|
|
266
|
-
function getSharp() {
|
|
267
|
-
const req = typeof require !== "undefined" ? require : module$1.createRequire(path__default.default.join(process.cwd(), "package.json"));
|
|
268
|
-
return req("sharp");
|
|
269
|
-
}
|
|
270
1229
|
function getCacheDir(strapi) {
|
|
271
1230
|
const rootDir = strapi?.dirs?.app?.root || process.cwd();
|
|
272
1231
|
const dir = path__default.default.join(rootDir, ".cache", "content-input-images");
|
|
@@ -275,47 +1234,12 @@ function getCacheDir(strapi) {
|
|
|
275
1234
|
}
|
|
276
1235
|
return dir;
|
|
277
1236
|
}
|
|
278
|
-
async function loadSourceBuffer(strapi, src) {
|
|
279
|
-
const publicDir = strapi?.dirs?.static?.public || path__default.default.join(process.cwd(), "public");
|
|
280
|
-
if (src.startsWith("/")) {
|
|
281
|
-
const cleanRel = decodeURIComponent(src.split("?")[0]).replace(/^\/+/, "");
|
|
282
|
-
const fullPath = path__default.default.resolve(publicDir, cleanRel);
|
|
283
|
-
const resolvedPublic = path__default.default.resolve(publicDir);
|
|
284
|
-
if (!fullPath.startsWith(resolvedPublic)) {
|
|
285
|
-
throw new Error("Invalid local file path");
|
|
286
|
-
}
|
|
287
|
-
if (!fs__default.default.existsSync(fullPath)) {
|
|
288
|
-
throw new Error(`File not found: ${src}`);
|
|
289
|
-
}
|
|
290
|
-
const buffer = await fs__default.default.promises.readFile(fullPath);
|
|
291
|
-
const ext = path__default.default.extname(fullPath).toLowerCase();
|
|
292
|
-
const mime = ext === ".png" ? "image/png" : ext === ".webp" ? "image/webp" : ext === ".avif" ? "image/avif" : ext === ".gif" ? "image/gif" : "image/jpeg";
|
|
293
|
-
return { buffer, mime };
|
|
294
|
-
}
|
|
295
|
-
if (/^https?:\/\//i.test(src)) {
|
|
296
|
-
const parsed = new URL(src);
|
|
297
|
-
if ((parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1") && parsed.pathname.startsWith("/uploads/")) {
|
|
298
|
-
const cleanRel = decodeURIComponent(parsed.pathname).replace(/^\/+/, "");
|
|
299
|
-
const fullPath = path__default.default.resolve(publicDir, cleanRel);
|
|
300
|
-
if (fs__default.default.existsSync(fullPath)) {
|
|
301
|
-
const buffer = await fs__default.default.promises.readFile(fullPath);
|
|
302
|
-
return { buffer, mime: "image/jpeg" };
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
const res = await fetch(src);
|
|
306
|
-
if (!res.ok) {
|
|
307
|
-
throw new Error(`Failed to fetch remote image (${res.status})`);
|
|
308
|
-
}
|
|
309
|
-
const contentType = res.headers.get("content-type") || "image/jpeg";
|
|
310
|
-
const arr = await res.arrayBuffer();
|
|
311
|
-
return { buffer: Buffer.from(arr), mime: contentType };
|
|
312
|
-
}
|
|
313
|
-
throw new Error("Unsupported image source URL");
|
|
314
|
-
}
|
|
315
1237
|
const ciImageController = ({ strapi }) => ({
|
|
316
1238
|
/**
|
|
317
1239
|
* GET /api/content-input/image & GET /content-input/image
|
|
318
|
-
*
|
|
1240
|
+
* Generates `ci-optimized` WebP variants via sharp, uploads to Strapi's Upload Provider (CDN),
|
|
1241
|
+
* persists in `plugin::upload.file.formats`, and issues a 302 redirect when a remote CDN URL is available
|
|
1242
|
+
* (with local byte-stream fallback in local-only environments).
|
|
319
1243
|
*/
|
|
320
1244
|
async processImage(ctx) {
|
|
321
1245
|
try {
|
|
@@ -324,16 +1248,96 @@ const ciImageController = ({ strapi }) => ({
|
|
|
324
1248
|
if (!src) {
|
|
325
1249
|
return ctx.badRequest("Missing src parameter");
|
|
326
1250
|
}
|
|
327
|
-
const
|
|
328
|
-
const
|
|
329
|
-
const
|
|
1251
|
+
const rawProc = String(query.process || "auto").trim().toLowerCase();
|
|
1252
|
+
const processMode = rawProc === "fit" ? "fit" : rawProc === "widen" ? "widen" : "auto";
|
|
1253
|
+
const w = Math.min(
|
|
1254
|
+
3840,
|
|
1255
|
+
Math.max(0, parseInt(String(query.w || query.cWidth || "0"), 10) || 0)
|
|
1256
|
+
);
|
|
1257
|
+
const h = Math.min(
|
|
1258
|
+
3840,
|
|
1259
|
+
Math.max(0, parseInt(String(query.h || query.cHeight || "0"), 10) || 0)
|
|
1260
|
+
);
|
|
330
1261
|
const q = Math.min(100, Math.max(20, parseInt(String(query.q || "85"), 10) || 85));
|
|
331
1262
|
const rotate = parseInt(String(query.rotate || "0"), 10) || 0;
|
|
332
1263
|
const cx = parseInt(String(query.x || "0"), 10) || 0;
|
|
333
1264
|
const cy = parseInt(String(query.y || "0"), 10) || 0;
|
|
334
1265
|
const cw = parseInt(String(query.cw || "0"), 10) || 0;
|
|
335
1266
|
const ch = parseInt(String(query.ch || "0"), 10) || 0;
|
|
336
|
-
const requestedFormat = String(query.format || "").toLowerCase();
|
|
1267
|
+
const requestedFormat = String(query.format || "").trim().toLowerCase();
|
|
1268
|
+
const acceptHeader = String(ctx.req?.headers?.accept || "");
|
|
1269
|
+
const wantsJson = query.json === "1" || query.json === "true" || acceptHeader.includes("application/json");
|
|
1270
|
+
const forceNoRedirect = query.redirect === "0" || query.redirect === "false" || query.proxy === "1" || query.proxy === "true";
|
|
1271
|
+
const forceRedirect = query.redirect === "1" || query.redirect === "true";
|
|
1272
|
+
const cfg = getVariantConfig(strapi);
|
|
1273
|
+
if (cw <= 0 && ch <= 0) {
|
|
1274
|
+
const existingFile = await findUploadFileForAsset(strapi, src);
|
|
1275
|
+
if (existingFile && existingFile.id) {
|
|
1276
|
+
if (!isOptimizableRasterImage(existingFile.mime, existingFile.ext || existingFile.url)) {
|
|
1277
|
+
const directUrl = existingFile.url;
|
|
1278
|
+
if (wantsJson) {
|
|
1279
|
+
ctx.body = { url: directUrl, formatKey: null };
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
if (!forceNoRedirect && directUrl && (cfg.redirectProxyToCdn && isAbsoluteHttpUrl(directUrl) || forceRedirect)) {
|
|
1283
|
+
ctx.set("Cache-Control", "public, max-age=86400");
|
|
1284
|
+
ctx.set("Access-Control-Allow-Origin", "*");
|
|
1285
|
+
ctx.status = 302;
|
|
1286
|
+
ctx.redirect(directUrl);
|
|
1287
|
+
return;
|
|
1288
|
+
}
|
|
1289
|
+
} else {
|
|
1290
|
+
const effW2 = w > 0 ? w : processMode === "auto" ? 1920 : 0;
|
|
1291
|
+
const effH2 = processMode === "fit" ? h : 0;
|
|
1292
|
+
if (effW2 > 0 || effH2 > 0) {
|
|
1293
|
+
const variantRes = await ensureMediaVariant(strapi, existingFile, {
|
|
1294
|
+
processMode,
|
|
1295
|
+
w: effW2,
|
|
1296
|
+
h: effH2,
|
|
1297
|
+
q,
|
|
1298
|
+
rotate,
|
|
1299
|
+
requestedFormat: requestedFormat || void 0
|
|
1300
|
+
});
|
|
1301
|
+
const providerUrl = variantRes.formatEntry?.url;
|
|
1302
|
+
if (providerUrl) {
|
|
1303
|
+
if (wantsJson) {
|
|
1304
|
+
ctx.body = {
|
|
1305
|
+
url: providerUrl,
|
|
1306
|
+
formatKey: variantRes.formatKey
|
|
1307
|
+
};
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
if (!forceNoRedirect && (cfg.redirectProxyToCdn && isAbsoluteHttpUrl(providerUrl) || forceRedirect)) {
|
|
1311
|
+
ctx.set("Cache-Control", "public, max-age=86400");
|
|
1312
|
+
ctx.set("Access-Control-Allow-Origin", "*");
|
|
1313
|
+
ctx.set("X-Content-Input-CDN-Url", providerUrl);
|
|
1314
|
+
ctx.status = 302;
|
|
1315
|
+
ctx.redirect(providerUrl);
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
try {
|
|
1319
|
+
const localVariant = await loadSourceBuffer(strapi, providerUrl);
|
|
1320
|
+
const etagLocal = `"ci-${variantRes.formatKey}-${existingFile.hash || existingFile.id}"`;
|
|
1321
|
+
if (ctx.req?.headers?.["if-none-match"] === etagLocal) {
|
|
1322
|
+
ctx.status = 304;
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
const resolvedMime = variantRes.formatEntry?.mime || localVariant.mime || "image/webp";
|
|
1326
|
+
ctx.body = localVariant.buffer;
|
|
1327
|
+
ctx.type = resolvedMime;
|
|
1328
|
+
ctx.set("Content-Type", resolvedMime);
|
|
1329
|
+
ctx.set("Cache-Control", "public, max-age=31536000, immutable");
|
|
1330
|
+
ctx.set("ETag", etagLocal);
|
|
1331
|
+
ctx.set("Access-Control-Allow-Origin", "*");
|
|
1332
|
+
ctx.set("X-Content-Input-CDN-Url", providerUrl);
|
|
1333
|
+
return;
|
|
1334
|
+
} catch {
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
337
1341
|
const cacheKeyRaw = JSON.stringify({
|
|
338
1342
|
src,
|
|
339
1343
|
processMode,
|
|
@@ -345,11 +1349,11 @@ const ciImageController = ({ strapi }) => ({
|
|
|
345
1349
|
cy,
|
|
346
1350
|
cw,
|
|
347
1351
|
ch,
|
|
348
|
-
requestedFormat
|
|
1352
|
+
requestedFormat: requestedFormat || cfg.defaultFormat
|
|
349
1353
|
});
|
|
350
1354
|
const hash = crypto__default.default.createHash("sha1").update(cacheKeyRaw).digest("hex");
|
|
351
1355
|
const etag = `"ci-${hash}"`;
|
|
352
|
-
if (ctx.req
|
|
1356
|
+
if (!wantsJson && ctx.req?.headers?.["if-none-match"] === etag) {
|
|
353
1357
|
ctx.status = 304;
|
|
354
1358
|
return;
|
|
355
1359
|
}
|
|
@@ -358,138 +1362,112 @@ const ciImageController = ({ strapi }) => ({
|
|
|
358
1362
|
const binPath = path__default.default.join(cacheDir, `${hash}.bin`);
|
|
359
1363
|
if (fs__default.default.existsSync(metaPath) && fs__default.default.existsSync(binPath)) {
|
|
360
1364
|
const meta = JSON.parse(await fs__default.default.promises.readFile(metaPath, "utf8"));
|
|
1365
|
+
if (meta.providerUrl) {
|
|
1366
|
+
if (wantsJson) {
|
|
1367
|
+
ctx.body = { url: meta.providerUrl, formatKey: meta.formatKey || null };
|
|
1368
|
+
return;
|
|
1369
|
+
}
|
|
1370
|
+
if (!forceNoRedirect && (cfg.redirectProxyToCdn && isAbsoluteHttpUrl(meta.providerUrl) || forceRedirect)) {
|
|
1371
|
+
ctx.set("Cache-Control", "public, max-age=86400");
|
|
1372
|
+
ctx.set("Access-Control-Allow-Origin", "*");
|
|
1373
|
+
ctx.set("X-Content-Input-CDN-Url", meta.providerUrl);
|
|
1374
|
+
ctx.status = 302;
|
|
1375
|
+
ctx.redirect(meta.providerUrl);
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
361
1379
|
const cachedBuffer = await fs__default.default.promises.readFile(binPath);
|
|
362
|
-
|
|
1380
|
+
const cachedMime = meta.contentType || "image/webp";
|
|
1381
|
+
ctx.body = cachedBuffer;
|
|
1382
|
+
ctx.type = cachedMime;
|
|
1383
|
+
ctx.set("Content-Type", cachedMime);
|
|
363
1384
|
ctx.set("Cache-Control", "public, max-age=31536000, immutable");
|
|
364
1385
|
ctx.set("ETag", etag);
|
|
365
1386
|
ctx.set("Access-Control-Allow-Origin", "*");
|
|
366
|
-
ctx.body = cachedBuffer;
|
|
367
1387
|
return;
|
|
368
1388
|
}
|
|
369
1389
|
const { buffer: sourceBuffer, mime: sourceMime } = await loadSourceBuffer(strapi, src);
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
position: "centre",
|
|
387
|
-
withoutEnlargement: false
|
|
388
|
-
});
|
|
389
|
-
} else if (processMode === "widen" && w > 0) {
|
|
390
|
-
pipeline = pipeline.resize(w, null, {
|
|
391
|
-
fit: "inside",
|
|
392
|
-
withoutEnlargement: false
|
|
393
|
-
});
|
|
394
|
-
} else if (w > 0 || h > 0) {
|
|
395
|
-
pipeline = pipeline.resize(w || null, h || null, {
|
|
396
|
-
fit: "inside",
|
|
397
|
-
withoutEnlargement: true
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
let outContentType = sourceMime;
|
|
401
|
-
if (requestedFormat === "webp" || sourceMime === "image/webp") {
|
|
402
|
-
pipeline = pipeline.webp({ quality: q });
|
|
403
|
-
outContentType = "image/webp";
|
|
404
|
-
} else if (requestedFormat === "avif" || sourceMime === "image/avif") {
|
|
405
|
-
pipeline = pipeline.avif({ quality: q });
|
|
406
|
-
outContentType = "image/avif";
|
|
407
|
-
} else if (requestedFormat === "png" || sourceMime === "image/png") {
|
|
408
|
-
pipeline = pipeline.png({ quality: q });
|
|
409
|
-
outContentType = "image/png";
|
|
410
|
-
} else {
|
|
411
|
-
pipeline = pipeline.jpeg({ quality: q, mozjpeg: true });
|
|
412
|
-
outContentType = "image/jpeg";
|
|
413
|
-
}
|
|
414
|
-
const outputBuffer = await pipeline.toBuffer();
|
|
415
|
-
let providerUrl;
|
|
416
|
-
try {
|
|
417
|
-
const cleanSrc = src.split("?")[0];
|
|
418
|
-
const existingFile = await strapi.db.query("plugin::upload.file").findOne({
|
|
419
|
-
where: { url: cleanSrc }
|
|
420
|
-
});
|
|
421
|
-
if (existingFile && existingFile.id) {
|
|
422
|
-
const formatKey = `ci_${processMode}_${w}x${h}${rotate ? `_r${rotate}` : ""}`;
|
|
423
|
-
const existingFormat = existingFile.formats?.[formatKey];
|
|
424
|
-
if (existingFormat?.url) {
|
|
425
|
-
providerUrl = existingFormat.url;
|
|
426
|
-
} else {
|
|
427
|
-
const outMeta = await sharp(outputBuffer).metadata();
|
|
428
|
-
const ext = outContentType === "image/png" ? ".png" : outContentType === "image/webp" ? ".webp" : outContentType === "image/avif" ? ".avif" : ".jpg";
|
|
429
|
-
const variantHash = `${formatKey}_${existingFile.hash || hash.slice(0, 10)}`;
|
|
430
|
-
const variantName = `${formatKey}_${existingFile.name || "image"}`;
|
|
431
|
-
const tmpVariantPath = path__default.default.join(os__default.default.tmpdir(), `${variantHash}${ext}`);
|
|
432
|
-
await fs__default.default.promises.writeFile(tmpVariantPath, outputBuffer);
|
|
433
|
-
try {
|
|
434
|
-
const variantFile = {
|
|
435
|
-
name: variantName,
|
|
436
|
-
hash: variantHash,
|
|
437
|
-
ext,
|
|
438
|
-
mime: outContentType,
|
|
439
|
-
filepath: tmpVariantPath,
|
|
440
|
-
path: existingFile.path || null,
|
|
441
|
-
getStream: () => fs__default.default.createReadStream(tmpVariantPath),
|
|
442
|
-
width: outMeta.width || w || void 0,
|
|
443
|
-
height: outMeta.height || h || void 0,
|
|
444
|
-
size: Math.round(outputBuffer.length / 1e3 * 100) / 100,
|
|
445
|
-
sizeInBytes: outputBuffer.length
|
|
446
|
-
};
|
|
447
|
-
const providerService = strapi.plugin("upload").service("provider");
|
|
448
|
-
if (providerService && typeof providerService.upload === "function") {
|
|
449
|
-
await providerService.upload(variantFile);
|
|
450
|
-
providerUrl = variantFile.url;
|
|
451
|
-
const { filepath: _fp, getStream: _gs, ...serializableFormat } = variantFile;
|
|
452
|
-
const nextFormats = {
|
|
453
|
-
...existingFile.formats || {},
|
|
454
|
-
[formatKey]: serializableFormat
|
|
455
|
-
};
|
|
456
|
-
await strapi.db.query("plugin::upload.file").update({
|
|
457
|
-
where: { id: existingFile.id },
|
|
458
|
-
data: { formats: nextFormats }
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
} finally {
|
|
462
|
-
await fs__default.default.promises.rm(tmpVariantPath, { force: true }).catch(() => void 0);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
} catch {
|
|
467
|
-
}
|
|
468
|
-
await fs__default.default.promises.writeFile(binPath, outputBuffer);
|
|
1390
|
+
const effW = w > 0 ? w : processMode === "auto" ? 1920 : 0;
|
|
1391
|
+
const effH = processMode === "fit" ? h : 0;
|
|
1392
|
+
const rendered = await renderSharpVariantBuffer(sourceBuffer, sourceMime, {
|
|
1393
|
+
processMode,
|
|
1394
|
+
w: effW,
|
|
1395
|
+
h: effH,
|
|
1396
|
+
q,
|
|
1397
|
+
rotate,
|
|
1398
|
+
cx,
|
|
1399
|
+
cy,
|
|
1400
|
+
cw,
|
|
1401
|
+
ch,
|
|
1402
|
+
requestedFormat: requestedFormat || void 0,
|
|
1403
|
+
defaultFormat: cfg.defaultFormat
|
|
1404
|
+
});
|
|
1405
|
+
await fs__default.default.promises.writeFile(binPath, rendered.buffer);
|
|
469
1406
|
await fs__default.default.promises.writeFile(
|
|
470
1407
|
metaPath,
|
|
471
1408
|
JSON.stringify({
|
|
472
|
-
contentType:
|
|
473
|
-
size:
|
|
474
|
-
providerUrl
|
|
1409
|
+
contentType: rendered.contentType,
|
|
1410
|
+
size: rendered.buffer.length
|
|
475
1411
|
})
|
|
476
1412
|
);
|
|
477
|
-
|
|
1413
|
+
if (wantsJson) {
|
|
1414
|
+
ctx.body = { url: src, formatKey: null };
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
ctx.body = rendered.buffer;
|
|
1418
|
+
ctx.type = rendered.contentType;
|
|
1419
|
+
ctx.set("Content-Type", rendered.contentType);
|
|
478
1420
|
ctx.set("Cache-Control", "public, max-age=31536000, immutable");
|
|
479
1421
|
ctx.set("ETag", etag);
|
|
480
1422
|
ctx.set("Access-Control-Allow-Origin", "*");
|
|
481
|
-
if (providerUrl) {
|
|
482
|
-
ctx.set("X-Content-Input-CDN-Url", providerUrl);
|
|
483
|
-
}
|
|
484
|
-
ctx.body = outputBuffer;
|
|
485
1423
|
} catch (err) {
|
|
486
1424
|
ctx.throw(400, err?.message || "Image processing error");
|
|
487
1425
|
}
|
|
488
1426
|
},
|
|
1427
|
+
/**
|
|
1428
|
+
* POST /content-input/media/optimize
|
|
1429
|
+
* Eagerly optimizes one or multiple selected/uploaded Media Library assets into `ci-optimized/*.webp`
|
|
1430
|
+
* on the configured Upload Provider (CDN) and returns enriched CIMediaAsset object(s) with `formats` & `optimized_url`.
|
|
1431
|
+
*/
|
|
1432
|
+
async optimizeMedia(ctx) {
|
|
1433
|
+
try {
|
|
1434
|
+
const body = ctx.request.body || {};
|
|
1435
|
+
const imageSettings = body.imageSettings || null;
|
|
1436
|
+
const defaultAutoMaxW = Number(body.defaultAutoMaxW) || 1920;
|
|
1437
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
1438
|
+
if (Array.isArray(body.assets)) {
|
|
1439
|
+
const enrichedList = [];
|
|
1440
|
+
for (const item of body.assets) {
|
|
1441
|
+
enrichedList.push(
|
|
1442
|
+
await enrichMediaAssetNode(strapi, item, {
|
|
1443
|
+
imageSettings,
|
|
1444
|
+
defaultAutoMaxW,
|
|
1445
|
+
fileCache
|
|
1446
|
+
})
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1449
|
+
ctx.body = { data: enrichedList };
|
|
1450
|
+
return;
|
|
1451
|
+
}
|
|
1452
|
+
if (body.asset) {
|
|
1453
|
+
const enriched = await enrichMediaAssetNode(strapi, body.asset, {
|
|
1454
|
+
imageSettings,
|
|
1455
|
+
defaultAutoMaxW,
|
|
1456
|
+
fileCache
|
|
1457
|
+
});
|
|
1458
|
+
ctx.body = { data: enriched };
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
return ctx.badRequest("asset or assets is required");
|
|
1462
|
+
} catch (err) {
|
|
1463
|
+
ctx.throw(500, err?.message || "Failed to optimize media asset");
|
|
1464
|
+
}
|
|
1465
|
+
},
|
|
489
1466
|
/**
|
|
490
1467
|
* POST /content-input/media/crop
|
|
491
1468
|
* Interactive crop & rotate using sharp on the backend (works seamlessly with local disk AND remote CDNs).
|
|
492
|
-
* Supports mode: 'replace' (crops original asset in Media Library
|
|
1469
|
+
* Supports mode: 'replace' (crops original asset in Media Library & refreshes ci-optimized variants)
|
|
1470
|
+
* or 'duplicate' (saves as new asset).
|
|
493
1471
|
*/
|
|
494
1472
|
async cropMedia(ctx) {
|
|
495
1473
|
const tmpDir = await fs__default.default.promises.mkdtemp(path__default.default.join(os__default.default.tmpdir(), "ci-crop-"));
|
|
@@ -545,7 +1523,7 @@ const ciImageController = ({ strapi }) => ({
|
|
|
545
1523
|
if (ext === ".png" || mime === "image/png") {
|
|
546
1524
|
pipeline = pipeline.png({ quality: 92 });
|
|
547
1525
|
} else if (ext === ".webp" || mime === "image/webp") {
|
|
548
|
-
pipeline = pipeline.webp({ quality: 90 });
|
|
1526
|
+
pipeline = pipeline.webp({ quality: 90, alphaQuality: 100 });
|
|
549
1527
|
} else {
|
|
550
1528
|
pipeline = pipeline.jpeg({ quality: 90, mozjpeg: true });
|
|
551
1529
|
}
|
|
@@ -554,6 +1532,9 @@ const ciImageController = ({ strapi }) => ({
|
|
|
554
1532
|
const targetFileName = mode === "duplicate" ? `${body.name || `${baseName}-cropped`}${ext.startsWith(".") ? ext : `.${ext}`}` : existingFile.name || `${baseName}${ext}`;
|
|
555
1533
|
const tmpFilePath = path__default.default.join(tmpDir, targetFileName);
|
|
556
1534
|
await fs__default.default.promises.writeFile(tmpFilePath, croppedBuffer);
|
|
1535
|
+
if (mode === "replace") {
|
|
1536
|
+
await clearGeneratedCiVariantsForFile(strapi, existingFile);
|
|
1537
|
+
}
|
|
557
1538
|
const uploadService = strapi.plugin("upload").service("upload");
|
|
558
1539
|
const fileInfo = {
|
|
559
1540
|
name: targetFileName,
|
|
@@ -589,6 +1570,17 @@ const ciImageController = ({ strapi }) => ({
|
|
|
589
1570
|
);
|
|
590
1571
|
resultFile = Array.isArray(uploaded) ? uploaded[0] : uploaded;
|
|
591
1572
|
}
|
|
1573
|
+
if (resultFile?.id) {
|
|
1574
|
+
try {
|
|
1575
|
+
const freshRes = await ensureMediaVariant(strapi, resultFile, {
|
|
1576
|
+
processMode: "auto",
|
|
1577
|
+
w: 1920,
|
|
1578
|
+
h: 0
|
|
1579
|
+
});
|
|
1580
|
+
resultFile = freshRes.updatedFile || resultFile;
|
|
1581
|
+
} catch {
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
592
1584
|
ctx.body = { data: resultFile };
|
|
593
1585
|
} catch (err) {
|
|
594
1586
|
ctx.throw(500, err?.message || "Failed to crop media asset");
|
|
@@ -760,9 +1752,8 @@ const ciFormController = ({ strapi }) => ({
|
|
|
760
1752
|
const { id } = ctx.params;
|
|
761
1753
|
const rawBody = ctx.request.body || {};
|
|
762
1754
|
const payload = rawBody && typeof rawBody.data === "object" && !Array.isArray(rawBody.data) && Object.keys(rawBody).length === 1 ? rawBody.data : rawBody;
|
|
763
|
-
const
|
|
764
|
-
const
|
|
765
|
-
const inferredLocale = (queryLocale || acceptLang || "tr").toLowerCase();
|
|
1755
|
+
const queryLocale = String(ctx.query?.locale || payload?._locale || "").trim();
|
|
1756
|
+
const inferredLocale = (queryLocale || "en").toLowerCase();
|
|
766
1757
|
const ip = String(ctx.request.headers?.["x-forwarded-for"] || "").split(",")[0].trim() || ctx.request.ip || "";
|
|
767
1758
|
const userAgent = String(ctx.request.headers?.["user-agent"] || "");
|
|
768
1759
|
const result = await strapi.plugin("content-input").service("ci-form").submitForm(id, payload, {
|
|
@@ -870,7 +1861,7 @@ const ciSurveyController = ({ strapi }) => ({
|
|
|
870
1861
|
const payload = rawBody && typeof rawBody.data === "object" && !Array.isArray(rawBody.data) && Object.keys(rawBody).length === 1 ? rawBody.data : rawBody;
|
|
871
1862
|
const acceptLang = String(ctx.request.headers?.["accept-language"] || "").split(",")[0].split(";")[0].trim();
|
|
872
1863
|
const queryLocale = String(ctx.query?.locale || "").trim();
|
|
873
|
-
const inferredLocale = (queryLocale || acceptLang || "
|
|
1864
|
+
const inferredLocale = (queryLocale || acceptLang || "en").toLowerCase();
|
|
874
1865
|
const ip = String(ctx.request.headers?.["x-forwarded-for"] || "").split(",")[0].trim() || ctx.request.ip || "";
|
|
875
1866
|
const userAgent = String(ctx.request.headers?.["user-agent"] || "");
|
|
876
1867
|
const result = await strapi.plugin("content-input").service("ci-survey").submitSurvey(id, payload, {
|
|
@@ -925,7 +1916,7 @@ const ciSurveyController = ({ strapi }) => ({
|
|
|
925
1916
|
try {
|
|
926
1917
|
const { id } = ctx.params;
|
|
927
1918
|
const format = String(ctx.query?.format || "csv").toLowerCase() === "json" ? "json" : "csv";
|
|
928
|
-
const locale = String(ctx.query?.locale || "
|
|
1919
|
+
const locale = String(ctx.query?.locale || "en").trim();
|
|
929
1920
|
const from = ctx.query?.from ? String(ctx.query.from) : void 0;
|
|
930
1921
|
const to = ctx.query?.to ? String(ctx.query.to) : void 0;
|
|
931
1922
|
const exported = await strapi.plugin("content-input").service("ci-survey").exportResponses(id, { format, locale, from, to });
|
|
@@ -949,12 +1940,112 @@ const ciSurveyController = ({ strapi }) => ({
|
|
|
949
1940
|
}
|
|
950
1941
|
}
|
|
951
1942
|
});
|
|
1943
|
+
const ciColorController = ({ strapi }) => ({
|
|
1944
|
+
async indexAdmin(ctx) {
|
|
1945
|
+
try {
|
|
1946
|
+
const res = await strapi.plugin("content-input").service("ci-color").findAll();
|
|
1947
|
+
ctx.body = res;
|
|
1948
|
+
} catch (err) {
|
|
1949
|
+
ctx.throw(500, err);
|
|
1950
|
+
}
|
|
1951
|
+
},
|
|
1952
|
+
async activePublic(ctx) {
|
|
1953
|
+
try {
|
|
1954
|
+
const slug = ctx.query?.slug ? String(ctx.query.slug) : void 0;
|
|
1955
|
+
const res = await strapi.plugin("content-input").service("ci-color").findActivePublic(slug);
|
|
1956
|
+
ctx.body = res;
|
|
1957
|
+
} catch (err) {
|
|
1958
|
+
ctx.throw(500, err);
|
|
1959
|
+
}
|
|
1960
|
+
},
|
|
1961
|
+
async save(ctx) {
|
|
1962
|
+
try {
|
|
1963
|
+
const body = ctx.request.body || {};
|
|
1964
|
+
const res = await strapi.plugin("content-input").service("ci-color").save(body);
|
|
1965
|
+
ctx.body = res;
|
|
1966
|
+
} catch (err) {
|
|
1967
|
+
ctx.throw(500, err);
|
|
1968
|
+
}
|
|
1969
|
+
},
|
|
1970
|
+
async activate(ctx) {
|
|
1971
|
+
try {
|
|
1972
|
+
const { id } = ctx.params || {};
|
|
1973
|
+
const res = await strapi.plugin("content-input").service("ci-color").activate(id);
|
|
1974
|
+
if (!res) {
|
|
1975
|
+
return ctx.notFound("Color palette not found");
|
|
1976
|
+
}
|
|
1977
|
+
ctx.body = res;
|
|
1978
|
+
} catch (err) {
|
|
1979
|
+
ctx.throw(500, err);
|
|
1980
|
+
}
|
|
1981
|
+
},
|
|
1982
|
+
async quickToken(ctx) {
|
|
1983
|
+
try {
|
|
1984
|
+
const body = ctx.request.body || {};
|
|
1985
|
+
if (!body.value) {
|
|
1986
|
+
return ctx.badRequest("Color value (HEX or RGB/RGBA) is required");
|
|
1987
|
+
}
|
|
1988
|
+
const res = await strapi.plugin("content-input").service("ci-color").upsertQuickCustomToken({
|
|
1989
|
+
key: body.key || body.label || "customColor",
|
|
1990
|
+
label: body.label,
|
|
1991
|
+
labels: body.labels,
|
|
1992
|
+
value: body.value
|
|
1993
|
+
});
|
|
1994
|
+
ctx.body = res;
|
|
1995
|
+
} catch (err) {
|
|
1996
|
+
ctx.throw(500, err);
|
|
1997
|
+
}
|
|
1998
|
+
},
|
|
1999
|
+
async delete(ctx) {
|
|
2000
|
+
try {
|
|
2001
|
+
const { id } = ctx.params || {};
|
|
2002
|
+
const res = await strapi.plugin("content-input").service("ci-color").remove(id);
|
|
2003
|
+
ctx.body = res;
|
|
2004
|
+
} catch (err) {
|
|
2005
|
+
ctx.badRequest(err?.message || "Unable to delete palette");
|
|
2006
|
+
}
|
|
2007
|
+
},
|
|
2008
|
+
async dataTableCollection(ctx) {
|
|
2009
|
+
try {
|
|
2010
|
+
const { uid, limit, sort } = ctx.query || {};
|
|
2011
|
+
if (!uid) {
|
|
2012
|
+
return ctx.badRequest('Query parameter "uid" is required');
|
|
2013
|
+
}
|
|
2014
|
+
const res = await strapi.plugin("content-input").service("ci-color").queryCollectionForDataTable({
|
|
2015
|
+
uid: String(uid),
|
|
2016
|
+
limit: limit ? Number(limit) : 25,
|
|
2017
|
+
sort: sort ? String(sort) : "createdAt:desc"
|
|
2018
|
+
});
|
|
2019
|
+
ctx.body = { data: res };
|
|
2020
|
+
} catch (err) {
|
|
2021
|
+
ctx.throw(500, err);
|
|
2022
|
+
}
|
|
2023
|
+
},
|
|
2024
|
+
async entityCardsBatch(ctx) {
|
|
2025
|
+
try {
|
|
2026
|
+
const { uid, documentIds, limit } = ctx.query || {};
|
|
2027
|
+
if (!uid) {
|
|
2028
|
+
return ctx.badRequest('Query parameter "uid" is required');
|
|
2029
|
+
}
|
|
2030
|
+
const docList = typeof documentIds === "string" && documentIds.trim() ? documentIds.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
2031
|
+
const items = await strapi.plugin("content-input").service("ci-color").resolveEntityCardsBatch({
|
|
2032
|
+
uid: String(uid),
|
|
2033
|
+
documentIds: docList,
|
|
2034
|
+
limit: limit ? Number(limit) : 6
|
|
2035
|
+
});
|
|
2036
|
+
ctx.body = { data: items };
|
|
2037
|
+
} catch (err) {
|
|
2038
|
+
ctx.throw(500, err);
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
952
2042
|
const controllers = {
|
|
953
2043
|
"ci-template": ciTemplateController,
|
|
954
2044
|
"ci-menu": ciMenuController,
|
|
955
2045
|
"ci-image": ciImageController,
|
|
956
2046
|
"ci-form": ciFormController,
|
|
957
|
-
"ci-survey": ciSurveyController
|
|
2047
|
+
"ci-survey": ciSurveyController,
|
|
2048
|
+
"ci-color": ciColorController
|
|
958
2049
|
};
|
|
959
2050
|
const routes = {
|
|
960
2051
|
admin: {
|
|
@@ -985,57 +2076,113 @@ const routes = {
|
|
|
985
2076
|
}
|
|
986
2077
|
},
|
|
987
2078
|
{
|
|
988
|
-
method: "DELETE",
|
|
989
|
-
path: "/templates/:id",
|
|
990
|
-
handler: "ci-template.delete",
|
|
2079
|
+
method: "DELETE",
|
|
2080
|
+
path: "/templates/:id",
|
|
2081
|
+
handler: "ci-template.delete",
|
|
2082
|
+
config: {
|
|
2083
|
+
policies: []
|
|
2084
|
+
}
|
|
2085
|
+
},
|
|
2086
|
+
{
|
|
2087
|
+
method: "GET",
|
|
2088
|
+
path: "/menus",
|
|
2089
|
+
handler: "ci-menu.index",
|
|
2090
|
+
config: {
|
|
2091
|
+
policies: []
|
|
2092
|
+
}
|
|
2093
|
+
},
|
|
2094
|
+
{
|
|
2095
|
+
method: "POST",
|
|
2096
|
+
path: "/menus",
|
|
2097
|
+
handler: "ci-menu.save",
|
|
2098
|
+
config: {
|
|
2099
|
+
policies: []
|
|
2100
|
+
}
|
|
2101
|
+
},
|
|
2102
|
+
{
|
|
2103
|
+
method: "DELETE",
|
|
2104
|
+
path: "/menus/:id",
|
|
2105
|
+
handler: "ci-menu.delete",
|
|
2106
|
+
config: {
|
|
2107
|
+
policies: []
|
|
2108
|
+
}
|
|
2109
|
+
},
|
|
2110
|
+
{
|
|
2111
|
+
method: "GET",
|
|
2112
|
+
path: "/entity-types",
|
|
2113
|
+
handler: "ci-menu.entityTypes",
|
|
2114
|
+
config: {
|
|
2115
|
+
policies: []
|
|
2116
|
+
}
|
|
2117
|
+
},
|
|
2118
|
+
{
|
|
2119
|
+
method: "GET",
|
|
2120
|
+
path: "/entities",
|
|
2121
|
+
handler: "ci-menu.entities",
|
|
2122
|
+
config: {
|
|
2123
|
+
policies: []
|
|
2124
|
+
}
|
|
2125
|
+
},
|
|
2126
|
+
{
|
|
2127
|
+
method: "GET",
|
|
2128
|
+
path: "/entity-card",
|
|
2129
|
+
handler: "ci-form.entityCard",
|
|
2130
|
+
config: {
|
|
2131
|
+
policies: []
|
|
2132
|
+
}
|
|
2133
|
+
},
|
|
2134
|
+
{
|
|
2135
|
+
method: "GET",
|
|
2136
|
+
path: "/entity-cards",
|
|
2137
|
+
handler: "ci-color.entityCardsBatch",
|
|
991
2138
|
config: {
|
|
992
2139
|
policies: []
|
|
993
2140
|
}
|
|
994
2141
|
},
|
|
995
2142
|
{
|
|
996
2143
|
method: "GET",
|
|
997
|
-
path: "/
|
|
998
|
-
handler: "ci-
|
|
2144
|
+
path: "/data-table",
|
|
2145
|
+
handler: "ci-color.dataTableCollection",
|
|
999
2146
|
config: {
|
|
1000
2147
|
policies: []
|
|
1001
2148
|
}
|
|
1002
2149
|
},
|
|
1003
2150
|
{
|
|
1004
|
-
method: "
|
|
1005
|
-
path: "/
|
|
1006
|
-
handler: "ci-
|
|
2151
|
+
method: "GET",
|
|
2152
|
+
path: "/color-codes",
|
|
2153
|
+
handler: "ci-color.indexAdmin",
|
|
1007
2154
|
config: {
|
|
1008
2155
|
policies: []
|
|
1009
2156
|
}
|
|
1010
2157
|
},
|
|
1011
2158
|
{
|
|
1012
|
-
method: "
|
|
1013
|
-
path: "/
|
|
1014
|
-
handler: "ci-
|
|
2159
|
+
method: "POST",
|
|
2160
|
+
path: "/color-codes",
|
|
2161
|
+
handler: "ci-color.save",
|
|
1015
2162
|
config: {
|
|
1016
2163
|
policies: []
|
|
1017
2164
|
}
|
|
1018
2165
|
},
|
|
1019
2166
|
{
|
|
1020
|
-
method: "
|
|
1021
|
-
path: "/
|
|
1022
|
-
handler: "ci-
|
|
2167
|
+
method: "POST",
|
|
2168
|
+
path: "/color-codes/quick-token",
|
|
2169
|
+
handler: "ci-color.quickToken",
|
|
1023
2170
|
config: {
|
|
1024
2171
|
policies: []
|
|
1025
2172
|
}
|
|
1026
2173
|
},
|
|
1027
2174
|
{
|
|
1028
|
-
method: "
|
|
1029
|
-
path: "/
|
|
1030
|
-
handler: "ci-
|
|
2175
|
+
method: "POST",
|
|
2176
|
+
path: "/color-codes/:id/activate",
|
|
2177
|
+
handler: "ci-color.activate",
|
|
1031
2178
|
config: {
|
|
1032
2179
|
policies: []
|
|
1033
2180
|
}
|
|
1034
2181
|
},
|
|
1035
2182
|
{
|
|
1036
|
-
method: "
|
|
1037
|
-
path: "/
|
|
1038
|
-
handler: "ci-
|
|
2183
|
+
method: "DELETE",
|
|
2184
|
+
path: "/color-codes/:id",
|
|
2185
|
+
handler: "ci-color.delete",
|
|
1039
2186
|
config: {
|
|
1040
2187
|
policies: []
|
|
1041
2188
|
}
|
|
@@ -1160,6 +2307,14 @@ const routes = {
|
|
|
1160
2307
|
policies: []
|
|
1161
2308
|
}
|
|
1162
2309
|
},
|
|
2310
|
+
{
|
|
2311
|
+
method: "POST",
|
|
2312
|
+
path: "/media/optimize",
|
|
2313
|
+
handler: "ci-image.optimizeMedia",
|
|
2314
|
+
config: {
|
|
2315
|
+
policies: []
|
|
2316
|
+
}
|
|
2317
|
+
},
|
|
1163
2318
|
{
|
|
1164
2319
|
method: "POST",
|
|
1165
2320
|
path: "/media/crop",
|
|
@@ -1304,6 +2459,33 @@ const routes = {
|
|
|
1304
2459
|
auth: false,
|
|
1305
2460
|
policies: []
|
|
1306
2461
|
}
|
|
2462
|
+
},
|
|
2463
|
+
{
|
|
2464
|
+
method: "GET",
|
|
2465
|
+
path: "/entity-cards",
|
|
2466
|
+
handler: "ci-color.entityCardsBatch",
|
|
2467
|
+
config: {
|
|
2468
|
+
auth: false,
|
|
2469
|
+
policies: []
|
|
2470
|
+
}
|
|
2471
|
+
},
|
|
2472
|
+
{
|
|
2473
|
+
method: "GET",
|
|
2474
|
+
path: "/data-table",
|
|
2475
|
+
handler: "ci-color.dataTableCollection",
|
|
2476
|
+
config: {
|
|
2477
|
+
auth: false,
|
|
2478
|
+
policies: []
|
|
2479
|
+
}
|
|
2480
|
+
},
|
|
2481
|
+
{
|
|
2482
|
+
method: "GET",
|
|
2483
|
+
path: "/color-codes",
|
|
2484
|
+
handler: "ci-color.activePublic",
|
|
2485
|
+
config: {
|
|
2486
|
+
auth: false,
|
|
2487
|
+
policies: []
|
|
2488
|
+
}
|
|
1307
2489
|
}
|
|
1308
2490
|
]
|
|
1309
2491
|
}
|
|
@@ -1320,7 +2502,7 @@ const ciTemplateService = ({ strapi }) => ({
|
|
|
1320
2502
|
}));
|
|
1321
2503
|
},
|
|
1322
2504
|
async create(data) {
|
|
1323
|
-
const structure = Array.isArray(data.structure) ? data.structure : [data.structure];
|
|
2505
|
+
const structure = data.category === "card_design" ? data.structure : Array.isArray(data.structure) ? data.structure : [data.structure];
|
|
1324
2506
|
const created = await strapi.db.query(UID).create({
|
|
1325
2507
|
data: {
|
|
1326
2508
|
name: String(data.name || "").trim(),
|
|
@@ -1368,7 +2550,7 @@ function slugifyTR(text) {
|
|
|
1368
2550
|
}
|
|
1369
2551
|
const DEFAULT_SEED_MENUS = [
|
|
1370
2552
|
{
|
|
1371
|
-
name: "
|
|
2553
|
+
name: "Main Header Navigation",
|
|
1372
2554
|
slug: "main-header-menu",
|
|
1373
2555
|
mode: "horizontal",
|
|
1374
2556
|
options: {
|
|
@@ -1380,7 +2562,7 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1380
2562
|
items: [
|
|
1381
2563
|
{
|
|
1382
2564
|
_uId: "m_home",
|
|
1383
|
-
title: "Ana Sayfa",
|
|
2565
|
+
title: { en: "Home", tr: "Ana Sayfa" },
|
|
1384
2566
|
url: "/",
|
|
1385
2567
|
type: "custom",
|
|
1386
2568
|
target: "_self",
|
|
@@ -1389,31 +2571,31 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1389
2571
|
},
|
|
1390
2572
|
{
|
|
1391
2573
|
_uId: "m_corp",
|
|
1392
|
-
title: "Kurumsal",
|
|
1393
|
-
url: "/
|
|
2574
|
+
title: { en: "Company", tr: "Kurumsal" },
|
|
2575
|
+
url: "/company",
|
|
1394
2576
|
type: "custom",
|
|
1395
2577
|
target: "_self",
|
|
1396
2578
|
icon: "business",
|
|
1397
2579
|
children: [
|
|
1398
2580
|
{
|
|
1399
2581
|
_uId: "m_about",
|
|
1400
|
-
title: "Hakkımızda",
|
|
1401
|
-
url: "/
|
|
2582
|
+
title: { en: "About Us", tr: "Hakkımızda" },
|
|
2583
|
+
url: "/company/about",
|
|
1402
2584
|
type: "custom",
|
|
1403
2585
|
target: "_self",
|
|
1404
2586
|
children: []
|
|
1405
2587
|
},
|
|
1406
2588
|
{
|
|
1407
2589
|
_uId: "m_vision",
|
|
1408
|
-
title: "Vizyon & Misyon",
|
|
1409
|
-
url: "/
|
|
2590
|
+
title: { en: "Vision & Mission", tr: "Vizyon & Misyon" },
|
|
2591
|
+
url: "/company/vision-mission",
|
|
1410
2592
|
type: "custom",
|
|
1411
2593
|
target: "_self",
|
|
1412
2594
|
children: [
|
|
1413
2595
|
{
|
|
1414
2596
|
_uId: "m_values",
|
|
1415
|
-
title: "Değerlerimiz & İlkelerimiz",
|
|
1416
|
-
url: "/
|
|
2597
|
+
title: { en: "Core Values & Principles", tr: "Değerlerimiz & İlkelerimiz" },
|
|
2598
|
+
url: "/company/values",
|
|
1417
2599
|
type: "custom",
|
|
1418
2600
|
target: "_self",
|
|
1419
2601
|
children: []
|
|
@@ -1422,8 +2604,8 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1422
2604
|
},
|
|
1423
2605
|
{
|
|
1424
2606
|
_uId: "m_board",
|
|
1425
|
-
title: "Yönetim Kurulu",
|
|
1426
|
-
url: "/
|
|
2607
|
+
title: { en: "Board of Directors", tr: "Yönetim Kurulu" },
|
|
2608
|
+
url: "/company/board",
|
|
1427
2609
|
type: "custom",
|
|
1428
2610
|
target: "_self",
|
|
1429
2611
|
children: []
|
|
@@ -1432,24 +2614,24 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1432
2614
|
},
|
|
1433
2615
|
{
|
|
1434
2616
|
_uId: "m_solutions",
|
|
1435
|
-
title: "Çözümlerimiz",
|
|
1436
|
-
url: "/
|
|
2617
|
+
title: { en: "Solutions", tr: "Çözümlerimiz" },
|
|
2618
|
+
url: "/solutions",
|
|
1437
2619
|
type: "custom",
|
|
1438
2620
|
target: "_self",
|
|
1439
2621
|
icon: "layers",
|
|
1440
2622
|
children: [
|
|
1441
2623
|
{
|
|
1442
2624
|
_uId: "m_sol_cms",
|
|
1443
|
-
title: "Kurumsal İçerik Yönetimi (CMS)",
|
|
1444
|
-
url: "/
|
|
2625
|
+
title: { en: "Enterprise Content Management (CMS)", tr: "Kurumsal İçerik Yönetimi (CMS)" },
|
|
2626
|
+
url: "/solutions/cms",
|
|
1445
2627
|
type: "custom",
|
|
1446
2628
|
target: "_self",
|
|
1447
2629
|
children: []
|
|
1448
2630
|
},
|
|
1449
2631
|
{
|
|
1450
2632
|
_uId: "m_sol_cloud",
|
|
1451
|
-
title: "Bulut & Mikroservis Mimarisi",
|
|
1452
|
-
url: "/
|
|
2633
|
+
title: { en: "Cloud & Microservice Architecture", tr: "Bulut & Mikroservis Mimarisi" },
|
|
2634
|
+
url: "/solutions/cloud",
|
|
1453
2635
|
type: "custom",
|
|
1454
2636
|
target: "_self",
|
|
1455
2637
|
children: []
|
|
@@ -1458,8 +2640,8 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1458
2640
|
},
|
|
1459
2641
|
{
|
|
1460
2642
|
_uId: "m_contact",
|
|
1461
|
-
title: "İletişim",
|
|
1462
|
-
url: "/
|
|
2643
|
+
title: { en: "Contact", tr: "İletişim" },
|
|
2644
|
+
url: "/contact",
|
|
1463
2645
|
type: "custom",
|
|
1464
2646
|
target: "_self",
|
|
1465
2647
|
icon: "mail",
|
|
@@ -1468,7 +2650,7 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1468
2650
|
]
|
|
1469
2651
|
},
|
|
1470
2652
|
{
|
|
1471
|
-
name: "
|
|
2653
|
+
name: "Corporate Sidebar Menu (Vertical Tree)",
|
|
1472
2654
|
slug: "corporate-sidebar-menu",
|
|
1473
2655
|
mode: "vertical",
|
|
1474
2656
|
options: {
|
|
@@ -1480,30 +2662,30 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1480
2662
|
items: [
|
|
1481
2663
|
{
|
|
1482
2664
|
_uId: "v_corp",
|
|
1483
|
-
title: "Kurumsal Bilgiler",
|
|
1484
|
-
url: "/
|
|
2665
|
+
title: { en: "Corporate Profile", tr: "Kurumsal Bilgiler" },
|
|
2666
|
+
url: "/company",
|
|
1485
2667
|
type: "custom",
|
|
1486
2668
|
target: "_self",
|
|
1487
2669
|
children: [
|
|
1488
2670
|
{
|
|
1489
2671
|
_uId: "v_history",
|
|
1490
|
-
title: "Tarihçemiz",
|
|
1491
|
-
url: "/
|
|
2672
|
+
title: { en: "Our History", tr: "Tarihçemiz" },
|
|
2673
|
+
url: "/company/history",
|
|
1492
2674
|
type: "custom",
|
|
1493
2675
|
target: "_self",
|
|
1494
2676
|
children: []
|
|
1495
2677
|
},
|
|
1496
2678
|
{
|
|
1497
2679
|
_uId: "v_quality",
|
|
1498
|
-
title: "Kalite Politikamız",
|
|
1499
|
-
url: "/
|
|
2680
|
+
title: { en: "Quality Policy", tr: "Kalite Politikamız" },
|
|
2681
|
+
url: "/company/quality",
|
|
1500
2682
|
type: "custom",
|
|
1501
2683
|
target: "_self",
|
|
1502
2684
|
children: [
|
|
1503
2685
|
{
|
|
1504
2686
|
_uId: "v_iso",
|
|
1505
|
-
title: "ISO 27001 & Sertifikalar",
|
|
1506
|
-
url: "/
|
|
2687
|
+
title: { en: "ISO 27001 & Certifications", tr: "ISO 27001 & Sertifikalar" },
|
|
2688
|
+
url: "/company/quality/certifications",
|
|
1507
2689
|
type: "custom",
|
|
1508
2690
|
target: "_self",
|
|
1509
2691
|
children: []
|
|
@@ -1514,8 +2696,8 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1514
2696
|
},
|
|
1515
2697
|
{
|
|
1516
2698
|
_uId: "v_career",
|
|
1517
|
-
title: "İnsan Kaynakları & Kariyer",
|
|
1518
|
-
url: "/
|
|
2699
|
+
title: { en: "Careers & Human Resources", tr: "İnsan Kaynakları & Kariyer" },
|
|
2700
|
+
url: "/careers",
|
|
1519
2701
|
type: "custom",
|
|
1520
2702
|
target: "_self",
|
|
1521
2703
|
children: []
|
|
@@ -1542,7 +2724,7 @@ const ciMenuService = ({ strapi }) => ({
|
|
|
1542
2724
|
}));
|
|
1543
2725
|
},
|
|
1544
2726
|
async save(data) {
|
|
1545
|
-
const cleanName = String(data.name || "
|
|
2727
|
+
const cleanName = String(data.name || "Menu").trim();
|
|
1546
2728
|
const cleanSlug = String(data.slug || slugifyTR(cleanName) || `menu-${Date.now()}`).trim();
|
|
1547
2729
|
const cleanMode = data.mode === "vertical" ? "vertical" : "horizontal";
|
|
1548
2730
|
const cleanItems = Array.isArray(data.items) ? data.items : [];
|
|
@@ -1780,13 +2962,13 @@ function splitValidationRules(validationStr) {
|
|
|
1780
2962
|
}
|
|
1781
2963
|
return merged;
|
|
1782
2964
|
}
|
|
1783
|
-
function resolveLocalizedText(val, locale = "
|
|
2965
|
+
function resolveLocalizedText(val, locale = "en", fallback = "") {
|
|
1784
2966
|
if (!val) return fallback;
|
|
1785
2967
|
if (typeof val === "string") return val;
|
|
1786
2968
|
if (typeof val === "object") {
|
|
1787
|
-
const code = String(locale || "
|
|
2969
|
+
const code = String(locale || "en").trim();
|
|
1788
2970
|
const shortCode = code.split(/[-_]/)[0];
|
|
1789
|
-
return val[code] || val[shortCode] || val.
|
|
2971
|
+
return val[code] || val[shortCode] || val.en || val.tr || Object.values(val).find((v) => typeof v === "string" && v.trim() !== "") || fallback;
|
|
1790
2972
|
}
|
|
1791
2973
|
return fallback;
|
|
1792
2974
|
}
|
|
@@ -1801,7 +2983,7 @@ function isEmptyFieldValue(value) {
|
|
|
1801
2983
|
function msg(locale, trText, enText) {
|
|
1802
2984
|
return String(locale || "").toLowerCase().startsWith("tr") ? trText : enText;
|
|
1803
2985
|
}
|
|
1804
|
-
function validateSingleField(value, field, allData = {}, locale = "
|
|
2986
|
+
function validateSingleField(value, field, allData = {}, locale = "en") {
|
|
1805
2987
|
const errors = [];
|
|
1806
2988
|
const rawValidation = typeof field.validation === "object" && field.validation !== null ? resolveLocalizedText(field.validation, locale, "") : String(field.validation || "");
|
|
1807
2989
|
const rules = splitValidationRules(rawValidation);
|
|
@@ -2048,7 +3230,7 @@ function validateSingleField(value, field, allData = {}, locale = "tr") {
|
|
|
2048
3230
|
}
|
|
2049
3231
|
return errors;
|
|
2050
3232
|
}
|
|
2051
|
-
function validateFormSubmission(fieldsMap, payload, locale = "
|
|
3233
|
+
function validateFormSubmission(fieldsMap, payload, locale = "en") {
|
|
2052
3234
|
const errors = {};
|
|
2053
3235
|
const data = payload || {};
|
|
2054
3236
|
for (const [key, fieldDef] of Object.entries(fieldsMap || {})) {
|
|
@@ -2102,25 +3284,28 @@ function escapeHtml(input) {
|
|
|
2102
3284
|
const str = input === null || input === void 0 ? "" : String(input);
|
|
2103
3285
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2104
3286
|
}
|
|
2105
|
-
function formatFieldValue(val) {
|
|
3287
|
+
function formatFieldValue(val, locale = "en") {
|
|
2106
3288
|
if (val === null || val === void 0 || val === "") return "-";
|
|
2107
3289
|
if (Array.isArray(val)) return val.join(", ");
|
|
2108
|
-
if (typeof val === "boolean")
|
|
3290
|
+
if (typeof val === "boolean") {
|
|
3291
|
+
const tr = String(locale || "en").toLowerCase().startsWith("tr");
|
|
3292
|
+
return val ? tr ? "Evet" : "Yes" : tr ? "Hayır" : "No";
|
|
3293
|
+
}
|
|
2109
3294
|
if (typeof val === "object") return JSON.stringify(val);
|
|
2110
3295
|
return String(val);
|
|
2111
3296
|
}
|
|
2112
3297
|
function renderContentFormMailHtml(params) {
|
|
2113
3298
|
const { form, data, meta } = params;
|
|
2114
|
-
const locale = meta?.locale || "
|
|
3299
|
+
const locale = meta?.locale || "en";
|
|
2115
3300
|
const fields = form.fields || {};
|
|
2116
3301
|
const entries = Object.keys(fields).length > 0 ? Object.entries(fields).map(([key, def]) => ({
|
|
2117
3302
|
key,
|
|
2118
3303
|
label: resolveLocalizedText(def?.alias, locale, key),
|
|
2119
|
-
value: formatFieldValue(data[key])
|
|
3304
|
+
value: formatFieldValue(data[key], locale)
|
|
2120
3305
|
})) : Object.entries(data || {}).map(([key, val]) => ({
|
|
2121
3306
|
key,
|
|
2122
3307
|
label: key,
|
|
2123
|
-
value: formatFieldValue(val)
|
|
3308
|
+
value: formatFieldValue(val, locale)
|
|
2124
3309
|
}));
|
|
2125
3310
|
const rowsHtml = entries.map(
|
|
2126
3311
|
(item) => `
|
|
@@ -2186,6 +3371,46 @@ function parseFromAddress(rawFrom, rawName) {
|
|
|
2186
3371
|
const name = (rawName || fallbackName).trim();
|
|
2187
3372
|
return { email: trimmed, name, formatted: `"${name}" <${trimmed}>` };
|
|
2188
3373
|
}
|
|
3374
|
+
const mailtrapInboxCache = /* @__PURE__ */ new Map();
|
|
3375
|
+
async function discoverMailtrapSandboxInbox(rawToken) {
|
|
3376
|
+
const token = String(rawToken || "").trim();
|
|
3377
|
+
if (!token) return "";
|
|
3378
|
+
if (mailtrapInboxCache.has(token)) {
|
|
3379
|
+
return mailtrapInboxCache.get(token) || "";
|
|
3380
|
+
}
|
|
3381
|
+
try {
|
|
3382
|
+
const accRes = await fetch("https://mailtrap.io/api/accounts", {
|
|
3383
|
+
headers: {
|
|
3384
|
+
Authorization: `Bearer ${token}`,
|
|
3385
|
+
"Api-Token": token
|
|
3386
|
+
}
|
|
3387
|
+
});
|
|
3388
|
+
if (!accRes.ok) return "";
|
|
3389
|
+
const accounts = await accRes.json();
|
|
3390
|
+
const accountId = Array.isArray(accounts) && accounts[0]?.id ? accounts[0].id : null;
|
|
3391
|
+
if (!accountId) return "";
|
|
3392
|
+
const inbRes = await fetch(
|
|
3393
|
+
`https://mailtrap.io/api/accounts/${encodeURIComponent(String(accountId))}/inboxes`,
|
|
3394
|
+
{
|
|
3395
|
+
headers: {
|
|
3396
|
+
Authorization: `Bearer ${token}`,
|
|
3397
|
+
"Api-Token": token
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
);
|
|
3401
|
+
if (!inbRes.ok) return "";
|
|
3402
|
+
const inboxes = await inbRes.json();
|
|
3403
|
+
if (!Array.isArray(inboxes) || inboxes.length === 0) return "";
|
|
3404
|
+
const activeInbox = inboxes.find((i) => i?.status === "active") || inboxes[0];
|
|
3405
|
+
const discoveredId = activeInbox?.id ? String(activeInbox.id) : "";
|
|
3406
|
+
if (discoveredId) {
|
|
3407
|
+
mailtrapInboxCache.set(token, discoveredId);
|
|
3408
|
+
}
|
|
3409
|
+
return discoveredId;
|
|
3410
|
+
} catch {
|
|
3411
|
+
return "";
|
|
3412
|
+
}
|
|
3413
|
+
}
|
|
2189
3414
|
async function sendDynamicFormMail(params) {
|
|
2190
3415
|
const { form, strapi } = params;
|
|
2191
3416
|
const cfg = form.mailConfig || {};
|
|
@@ -2213,7 +3438,8 @@ async function sendDynamicFormMail(params) {
|
|
|
2213
3438
|
cfg.from || process.env.MAIL_FROM,
|
|
2214
3439
|
cfg.fromName || process.env.MAIL_FROM_NAME
|
|
2215
3440
|
);
|
|
2216
|
-
const
|
|
3441
|
+
const isTr = String(params.meta?.locale || "en").toLowerCase().startsWith("tr");
|
|
3442
|
+
const subject = form.subject?.trim() || `${form.title} — ${isTr ? "Yeni Form Başvurusu" : "New Form Submission"}`;
|
|
2217
3443
|
const { html, text } = renderContentFormMailHtml(params);
|
|
2218
3444
|
let resolvedDriver = explicitDriver;
|
|
2219
3445
|
if (resolvedDriver === "auto") {
|
|
@@ -2225,11 +3451,17 @@ async function sendDynamicFormMail(params) {
|
|
|
2225
3451
|
try {
|
|
2226
3452
|
if (resolvedDriver === "mailtrap") {
|
|
2227
3453
|
if (mailtrapToken) {
|
|
2228
|
-
const
|
|
3454
|
+
const cleanToken = mailtrapToken.trim();
|
|
3455
|
+
let effectiveInboxId = mailtrapInboxId ? String(mailtrapInboxId).trim() : "";
|
|
3456
|
+
if (!effectiveInboxId) {
|
|
3457
|
+
effectiveInboxId = await discoverMailtrapSandboxInbox(cleanToken);
|
|
3458
|
+
}
|
|
3459
|
+
const endpoint = effectiveInboxId ? `https://sandbox.api.mailtrap.io/api/send/${encodeURIComponent(effectiveInboxId)}` : "https://send.api.mailtrap.io/api/send";
|
|
2229
3460
|
const res = await fetch(endpoint, {
|
|
2230
3461
|
method: "POST",
|
|
2231
3462
|
headers: {
|
|
2232
|
-
Authorization: `Bearer ${
|
|
3463
|
+
Authorization: `Bearer ${cleanToken}`,
|
|
3464
|
+
"Api-Token": cleanToken,
|
|
2233
3465
|
"Content-Type": "application/json"
|
|
2234
3466
|
},
|
|
2235
3467
|
body: JSON.stringify({
|
|
@@ -2246,7 +3478,7 @@ async function sendDynamicFormMail(params) {
|
|
|
2246
3478
|
}
|
|
2247
3479
|
return {
|
|
2248
3480
|
sent: true,
|
|
2249
|
-
driver:
|
|
3481
|
+
driver: effectiveInboxId ? "mailtrap-sandbox-api" : "mailtrap-sending-api",
|
|
2250
3482
|
detail: resBody
|
|
2251
3483
|
};
|
|
2252
3484
|
}
|
|
@@ -2374,10 +3606,10 @@ async function sendDynamicFormMail(params) {
|
|
|
2374
3606
|
}
|
|
2375
3607
|
const DEFAULT_SEED_SURVEYS = [
|
|
2376
3608
|
{
|
|
2377
|
-
title: "
|
|
3609
|
+
title: "Enterprise Product & Developer Experience Survey (3-Step)",
|
|
2378
3610
|
titleI18n: {
|
|
2379
|
-
|
|
2380
|
-
|
|
3611
|
+
en: "Enterprise Product & Developer Experience Survey",
|
|
3612
|
+
tr: "Kurumsal Ürün & Geliştirici Deneyimi Anketi"
|
|
2381
3613
|
},
|
|
2382
3614
|
slug: "showcase_dx_survey",
|
|
2383
3615
|
description: {
|
|
@@ -2713,10 +3945,10 @@ const DEFAULT_SEED_SURVEYS = [
|
|
|
2713
3945
|
}
|
|
2714
3946
|
},
|
|
2715
3947
|
{
|
|
2716
|
-
title: "
|
|
3948
|
+
title: "Quick Poll: What Should We Ship Next?",
|
|
2717
3949
|
titleI18n: {
|
|
2718
|
-
|
|
2719
|
-
|
|
3950
|
+
en: "Quick Poll: What Should We Ship Next?",
|
|
3951
|
+
tr: "Hızlı Oylama: Sıradaki Büyük Özellik Ne Olsun?"
|
|
2720
3952
|
},
|
|
2721
3953
|
slug: "showcase_roadmap_poll",
|
|
2722
3954
|
description: {
|
|
@@ -2787,10 +4019,10 @@ const DEFAULT_SEED_SURVEYS = [
|
|
|
2787
4019
|
}
|
|
2788
4020
|
},
|
|
2789
4021
|
{
|
|
2790
|
-
title: "
|
|
4022
|
+
title: "Visual Showcase & Readability Poll (Live Results)",
|
|
2791
4023
|
titleI18n: {
|
|
2792
|
-
|
|
2793
|
-
|
|
4024
|
+
en: "Visual Showcase & Readability Poll (Live Results)",
|
|
4025
|
+
tr: "Görsel Vitrin & Okunabilirlik Tercihi (Açık Sonuçlu)"
|
|
2794
4026
|
},
|
|
2795
4027
|
slug: "showcase_visual_theme_poll",
|
|
2796
4028
|
description: {
|
|
@@ -3291,7 +4523,7 @@ const DEFAULT_SEED_FORMS = [
|
|
|
3291
4523
|
title: "Enterprise Inquiry & Support Form",
|
|
3292
4524
|
slug: "showcase_contact_form",
|
|
3293
4525
|
to: "info@example.com",
|
|
3294
|
-
subject: "
|
|
4526
|
+
subject: "Enterprise Inquiry & Support Submission",
|
|
3295
4527
|
buttonLabel: {
|
|
3296
4528
|
tr: "Başvuruyu Gönder",
|
|
3297
4529
|
en: "Submit Inquiry"
|
|
@@ -3586,8 +4818,8 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3586
4818
|
} catch {
|
|
3587
4819
|
}
|
|
3588
4820
|
return [
|
|
3589
|
-
{ code: "
|
|
3590
|
-
{ code: "
|
|
4821
|
+
{ code: "en", name: "English (en)", isDefault: true },
|
|
4822
|
+
{ code: "tr", name: "Türkçe (tr)", isDefault: false }
|
|
3591
4823
|
];
|
|
3592
4824
|
},
|
|
3593
4825
|
async ensureSampleSubmissions(force = false) {
|
|
@@ -3621,6 +4853,22 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3621
4853
|
for (const seed of DEFAULT_SEED_FORMS) {
|
|
3622
4854
|
await strapi.db.query(FORM_UID).create({ data: seed });
|
|
3623
4855
|
}
|
|
4856
|
+
} else {
|
|
4857
|
+
try {
|
|
4858
|
+
const showcase = await strapi.db.query(FORM_UID).findOne({
|
|
4859
|
+
where: { slug: "showcase_contact_form" }
|
|
4860
|
+
});
|
|
4861
|
+
if (showcase && (showcase.subject === "Kurumsal İletişim & Destek Başvurusu" || showcase.title === "Kurumsal İletişim & Destek Formu")) {
|
|
4862
|
+
await strapi.db.query(FORM_UID).update({
|
|
4863
|
+
where: { id: showcase.id },
|
|
4864
|
+
data: {
|
|
4865
|
+
title: "Enterprise Inquiry & Support Form",
|
|
4866
|
+
subject: "Enterprise Inquiry & Support Submission"
|
|
4867
|
+
}
|
|
4868
|
+
});
|
|
4869
|
+
}
|
|
4870
|
+
} catch {
|
|
4871
|
+
}
|
|
3624
4872
|
}
|
|
3625
4873
|
await this.ensureSampleSubmissions(false);
|
|
3626
4874
|
},
|
|
@@ -3664,7 +4912,7 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3664
4912
|
return sanitizeFormForPublic(found);
|
|
3665
4913
|
},
|
|
3666
4914
|
async save(payload) {
|
|
3667
|
-
const cleanTitle = String(payload.title || "
|
|
4915
|
+
const cleanTitle = String(payload.title || "New Dynamic Form").trim();
|
|
3668
4916
|
const cleanSlug = String(
|
|
3669
4917
|
payload.slug || slugifyIdentifier$1(cleanTitle) || `form_${Date.now()}`
|
|
3670
4918
|
).trim();
|
|
@@ -3681,6 +4929,16 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3681
4929
|
if (!existing && cleanSlug) {
|
|
3682
4930
|
existing = await strapi.db.query(FORM_UID).findOne({ where: { slug: cleanSlug } });
|
|
3683
4931
|
}
|
|
4932
|
+
const mergedMailConfig = {
|
|
4933
|
+
...existing?.mailConfig || { driver: "env" },
|
|
4934
|
+
...payload.mailConfig || {}
|
|
4935
|
+
};
|
|
4936
|
+
if (mergedMailConfig.driver === "mailtrap" && mergedMailConfig.apiKey && !String(mergedMailConfig.inboxId || "").trim()) {
|
|
4937
|
+
const autoInbox = await discoverMailtrapSandboxInbox(mergedMailConfig.apiKey);
|
|
4938
|
+
if (autoInbox) {
|
|
4939
|
+
mergedMailConfig.inboxId = autoInbox;
|
|
4940
|
+
}
|
|
4941
|
+
}
|
|
3684
4942
|
const recordData = {
|
|
3685
4943
|
title: cleanTitle,
|
|
3686
4944
|
slug: cleanSlug,
|
|
@@ -3699,7 +4957,7 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3699
4957
|
useRecaptcha: payload.useRecaptcha !== void 0 ? Boolean(payload.useRecaptcha) : existing?.useRecaptcha !== void 0 ? Boolean(existing.useRecaptcha) : true,
|
|
3700
4958
|
recaptchaSiteKey: payload.recaptchaSiteKey !== void 0 ? String(payload.recaptchaSiteKey) : existing?.recaptchaSiteKey || "",
|
|
3701
4959
|
recaptchaSecretKey: payload.recaptchaSecretKey !== void 0 ? String(payload.recaptchaSecretKey) : existing?.recaptchaSecretKey || "",
|
|
3702
|
-
mailConfig:
|
|
4960
|
+
mailConfig: mergedMailConfig,
|
|
3703
4961
|
fields: payload.fields && typeof payload.fields === "object" ? payload.fields : existing?.fields || {},
|
|
3704
4962
|
form: Array.isArray(payload.form) ? payload.form : existing?.form || []
|
|
3705
4963
|
};
|
|
@@ -3768,8 +5026,8 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3768
5026
|
};
|
|
3769
5027
|
}
|
|
3770
5028
|
const body = rawBody && typeof rawBody === "object" ? rawBody : {};
|
|
3771
|
-
const rawLocale = String(body._locale || meta.locale || "
|
|
3772
|
-
const locale = rawLocale ? rawLocale.split(/[,;]/)[0].trim() : "
|
|
5029
|
+
const rawLocale = String(body._locale || meta.locale || "en").trim().toLowerCase();
|
|
5030
|
+
const locale = rawLocale ? rawLocale.split(/[,;]/)[0].trim() : "en";
|
|
3773
5031
|
const fieldsMap = form.fields && typeof form.fields === "object" ? form.fields : {};
|
|
3774
5032
|
const { errors } = validateFormSubmission(fieldsMap, body, locale);
|
|
3775
5033
|
const activeSecretKey = String(
|
|
@@ -3978,6 +5236,14 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3978
5236
|
}
|
|
3979
5237
|
}
|
|
3980
5238
|
}
|
|
5239
|
+
if (imageObj) {
|
|
5240
|
+
try {
|
|
5241
|
+
imageObj = await enrichMediaAssetNode(strapi, imageObj, {
|
|
5242
|
+
defaultAutoMaxW: 960
|
|
5243
|
+
});
|
|
5244
|
+
} catch {
|
|
5245
|
+
}
|
|
5246
|
+
}
|
|
3981
5247
|
const pluralName = ct.info?.pluralName || "items";
|
|
3982
5248
|
const slugField = ["slug", "path", "url", "permalink"].find(
|
|
3983
5249
|
(k) => typeof entry[k] === "string" && entry[k].trim()
|
|
@@ -4066,7 +5332,7 @@ function isQuestionVisible(question, survey, answers) {
|
|
|
4066
5332
|
function lMsg(locale, tr, en) {
|
|
4067
5333
|
return String(locale || "").toLowerCase().startsWith("tr") ? tr : en;
|
|
4068
5334
|
}
|
|
4069
|
-
function validateSurveySubmission(survey, answers, otherTexts = {}, locale = "
|
|
5335
|
+
function validateSurveySubmission(survey, answers, otherTexts = {}, locale = "en") {
|
|
4070
5336
|
const errors = {};
|
|
4071
5337
|
const questions = Array.isArray(survey.questions) ? survey.questions : [];
|
|
4072
5338
|
for (const q of questions) {
|
|
@@ -4262,7 +5528,7 @@ function computeSurveyAnalytics(survey, rawResponses, filter = {}) {
|
|
|
4262
5528
|
const dailyCounts = {};
|
|
4263
5529
|
let lastSubmittedAt = null;
|
|
4264
5530
|
for (const r of responses) {
|
|
4265
|
-
const loc = String(r.locale || "
|
|
5531
|
+
const loc = String(r.locale || "en");
|
|
4266
5532
|
localeCounts[loc] = (localeCounts[loc] || 0) + 1;
|
|
4267
5533
|
const tsRaw = r.submittedAt || r.createdAt;
|
|
4268
5534
|
if (tsRaw) {
|
|
@@ -4324,7 +5590,7 @@ function computeSurveyAnalytics(survey, rawResponses, filter = {}) {
|
|
|
4324
5590
|
if (txt && otherSamples.length < 30) {
|
|
4325
5591
|
otherSamples.push({
|
|
4326
5592
|
text: txt,
|
|
4327
|
-
locale: r.locale || "
|
|
5593
|
+
locale: r.locale || "en",
|
|
4328
5594
|
submittedAt: r.submittedAt || r.createdAt || ""
|
|
4329
5595
|
});
|
|
4330
5596
|
}
|
|
@@ -4531,7 +5797,7 @@ function computeSurveyAnalytics(survey, rawResponses, filter = {}) {
|
|
|
4531
5797
|
textResponses.push({
|
|
4532
5798
|
id: r.id || r.documentId,
|
|
4533
5799
|
text: v.trim(),
|
|
4534
|
-
locale: r.locale || "
|
|
5800
|
+
locale: r.locale || "en",
|
|
4535
5801
|
submittedAt: r.submittedAt || r.createdAt || "",
|
|
4536
5802
|
npsValue: r.npsValue ?? null
|
|
4537
5803
|
});
|
|
@@ -4594,7 +5860,7 @@ function escapeCsvCell(val) {
|
|
|
4594
5860
|
}
|
|
4595
5861
|
return str;
|
|
4596
5862
|
}
|
|
4597
|
-
function exportSurveyResponsesToCsv(survey, rawResponses, locale = "
|
|
5863
|
+
function exportSurveyResponsesToCsv(survey, rawResponses, locale = "en") {
|
|
4598
5864
|
const activeQuestions = (survey.questions || []).filter((q) => q && q.type !== "statement");
|
|
4599
5865
|
const headers = [
|
|
4600
5866
|
"Response ID",
|
|
@@ -4977,6 +6243,12 @@ const ciSurveyService = ({ strapi }) => ({
|
|
|
4977
6243
|
settings: payload.settings ?? existing?.settings ?? {},
|
|
4978
6244
|
version: existing ? Number(existing.version || 1) + 1 : 1
|
|
4979
6245
|
};
|
|
6246
|
+
if (Array.isArray(recordData.questions) && recordData.questions.length > 0) {
|
|
6247
|
+
try {
|
|
6248
|
+
recordData.questions = await syncSurveyQuestionsMedia(strapi, recordData.questions);
|
|
6249
|
+
} catch {
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
4980
6252
|
if (existing) {
|
|
4981
6253
|
const updated = await strapi.db.query(SURVEY_UID).update({
|
|
4982
6254
|
where: { id: existing.id },
|
|
@@ -5010,8 +6282,8 @@ const ciSurveyService = ({ strapi }) => ({
|
|
|
5010
6282
|
};
|
|
5011
6283
|
}
|
|
5012
6284
|
const body = rawBody && typeof rawBody === "object" ? rawBody : {};
|
|
5013
|
-
const rawLocale = String(body._locale || meta.locale || "
|
|
5014
|
-
const locale = rawLocale ? rawLocale.split(/[,;]/)[0].trim() : "
|
|
6285
|
+
const rawLocale = String(body._locale || meta.locale || "en").trim().toLowerCase();
|
|
6286
|
+
const locale = rawLocale ? rawLocale.split(/[,;]/)[0].trim() : "en";
|
|
5015
6287
|
const isTr = locale.startsWith("tr");
|
|
5016
6288
|
if (body._hp && String(body._hp).trim() !== "") {
|
|
5017
6289
|
return {
|
|
@@ -5150,7 +6422,7 @@ const ciSurveyService = ({ strapi }) => ({
|
|
|
5150
6422
|
form: {
|
|
5151
6423
|
title: survey.title,
|
|
5152
6424
|
to: notifyEmails,
|
|
5153
|
-
subject:
|
|
6425
|
+
subject: `${isTr ? "[Anket Yanıtı]" : "[Survey Response]"} ${survey.title}`,
|
|
5154
6426
|
mailConfig: survey.mailConfig
|
|
5155
6427
|
},
|
|
5156
6428
|
data: {
|
|
@@ -5259,7 +6531,7 @@ const ciSurveyService = ({ strapi }) => ({
|
|
|
5259
6531
|
const csv = exportSurveyResponsesToCsv(
|
|
5260
6532
|
survey,
|
|
5261
6533
|
responses,
|
|
5262
|
-
options2.locale || "
|
|
6534
|
+
options2.locale || "en"
|
|
5263
6535
|
);
|
|
5264
6536
|
return {
|
|
5265
6537
|
filename: `${survey.slug}-responses.csv`,
|
|
@@ -5268,11 +6540,615 @@ const ciSurveyService = ({ strapi }) => ({
|
|
|
5268
6540
|
};
|
|
5269
6541
|
}
|
|
5270
6542
|
});
|
|
6543
|
+
const PALETTE_UID = "plugin::content-input.ci-color-palette";
|
|
6544
|
+
function clamp(n, min, max) {
|
|
6545
|
+
return Math.max(min, Math.min(max, n));
|
|
6546
|
+
}
|
|
6547
|
+
function parseColorToRgba(rawInput, fallback = { r: 79, g: 70, b: 229, a: 1 }) {
|
|
6548
|
+
const str = String(rawInput || "").trim();
|
|
6549
|
+
if (!str) return fallback;
|
|
6550
|
+
const varMatch = str.match(/^var\([^,]+,\s*(.+)\)$/);
|
|
6551
|
+
const target = varMatch ? varMatch[1].trim() : str;
|
|
6552
|
+
const hexMatch = target.match(/^#([0-9a-fA-F]{3,8})$/);
|
|
6553
|
+
if (hexMatch) {
|
|
6554
|
+
const h = hexMatch[1];
|
|
6555
|
+
if (h.length === 3 || h.length === 4) {
|
|
6556
|
+
const r = parseInt(h[0] + h[0], 16);
|
|
6557
|
+
const g = parseInt(h[1] + h[1], 16);
|
|
6558
|
+
const b = parseInt(h[2] + h[2], 16);
|
|
6559
|
+
const a = h.length === 4 ? Number((parseInt(h[3] + h[3], 16) / 255).toFixed(2)) : 1;
|
|
6560
|
+
return { r, g, b, a };
|
|
6561
|
+
}
|
|
6562
|
+
if (h.length === 6 || h.length === 8) {
|
|
6563
|
+
const r = parseInt(h.slice(0, 2), 16);
|
|
6564
|
+
const g = parseInt(h.slice(2, 4), 16);
|
|
6565
|
+
const b = parseInt(h.slice(4, 6), 16);
|
|
6566
|
+
const a = h.length === 8 ? Number((parseInt(h.slice(6, 8), 16) / 255).toFixed(2)) : 1;
|
|
6567
|
+
return { r, g, b, a };
|
|
6568
|
+
}
|
|
6569
|
+
}
|
|
6570
|
+
const rgbMatch = target.match(/^rgba?\(\s*([\d.]+)\s*[,\s]\s*([\d.]+)\s*[,\s]\s*([\d.]+)(?:\s*[,/]\s*([\d.%]+))?\s*\)$/i);
|
|
6571
|
+
if (rgbMatch) {
|
|
6572
|
+
const r = clamp(Math.round(Number(rgbMatch[1])), 0, 255);
|
|
6573
|
+
const g = clamp(Math.round(Number(rgbMatch[2])), 0, 255);
|
|
6574
|
+
const b = clamp(Math.round(Number(rgbMatch[3])), 0, 255);
|
|
6575
|
+
let a = 1;
|
|
6576
|
+
if (rgbMatch[4] !== void 0) {
|
|
6577
|
+
const rawA = rgbMatch[4].trim();
|
|
6578
|
+
a = rawA.endsWith("%") ? clamp(Number(rawA.slice(0, -1)) / 100, 0, 1) : clamp(Number(rawA), 0, 1);
|
|
6579
|
+
a = Number(a.toFixed(2));
|
|
6580
|
+
}
|
|
6581
|
+
return { r, g, b, a };
|
|
6582
|
+
}
|
|
6583
|
+
return fallback;
|
|
6584
|
+
}
|
|
6585
|
+
function rgbaToHex({ r, g, b, a }) {
|
|
6586
|
+
const to2 = (n) => clamp(Math.round(n), 0, 255).toString(16).padStart(2, "0");
|
|
6587
|
+
if (a < 1) {
|
|
6588
|
+
return `#${to2(r)}${to2(g)}${to2(b)}${to2(Math.round(a * 255))}`;
|
|
6589
|
+
}
|
|
6590
|
+
return `#${to2(r)}${to2(g)}${to2(b)}`;
|
|
6591
|
+
}
|
|
6592
|
+
function rgbaToCssString({ r, g, b, a }) {
|
|
6593
|
+
const cr = clamp(Math.round(r), 0, 255);
|
|
6594
|
+
const cg = clamp(Math.round(g), 0, 255);
|
|
6595
|
+
const cb = clamp(Math.round(b), 0, 255);
|
|
6596
|
+
const ca = clamp(Number(a.toFixed(2)), 0, 1);
|
|
6597
|
+
return ca < 1 ? `rgba(${cr}, ${cg}, ${cb}, ${ca})` : `rgb(${cr}, ${cg}, ${cb})`;
|
|
6598
|
+
}
|
|
6599
|
+
function buildTokenEntry(rawVal, labels, overrides) {
|
|
6600
|
+
const parsed = parseColorToRgba(rawVal);
|
|
6601
|
+
const hex = rgbaToHex(parsed);
|
|
6602
|
+
const rgb = rgbaToCssString(parsed);
|
|
6603
|
+
const cleanTrimmed = String(rawVal || "").trim();
|
|
6604
|
+
const value = cleanTrimmed.toLowerCase().startsWith("rgb") ? rgb : hex;
|
|
6605
|
+
const srgb = [parsed.r, parsed.g, parsed.b].map((v) => {
|
|
6606
|
+
const c = v / 255;
|
|
6607
|
+
return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
6608
|
+
});
|
|
6609
|
+
const lum = 0.2126 * srgb[0] + 0.7152 * srgb[1] + 0.0722 * srgb[2];
|
|
6610
|
+
const autoContrast = lum > 0.44 ? "#0f172a" : "#ffffff";
|
|
6611
|
+
const autoSoft = `rgba(${parsed.r}, ${parsed.g}, ${parsed.b}, 0.14)`;
|
|
6612
|
+
return {
|
|
6613
|
+
value,
|
|
6614
|
+
hex,
|
|
6615
|
+
rgb,
|
|
6616
|
+
soft: overrides?.soft || autoSoft,
|
|
6617
|
+
contrast: overrides?.contrast || autoContrast,
|
|
6618
|
+
...labels ? { labels } : {}
|
|
6619
|
+
};
|
|
6620
|
+
}
|
|
6621
|
+
const SEMANTIC_TOKEN_META = [
|
|
6622
|
+
{ key: "primary", tr: "Birincil (Primary)", en: "Primary" },
|
|
6623
|
+
{ key: "secondary", tr: "İkincil (Secondary)", en: "Secondary" },
|
|
6624
|
+
{ key: "accent", tr: "Vurgu (Accent)", en: "Accent" },
|
|
6625
|
+
{ key: "success", tr: "Başarı (Success)", en: "Success" },
|
|
6626
|
+
{ key: "warning", tr: "Uyarı (Warning)", en: "Warning" },
|
|
6627
|
+
{ key: "error", tr: "Hata / Tehlike (Error)", en: "Error" },
|
|
6628
|
+
{ key: "info", tr: "Bilgi (Info)", en: "Info" },
|
|
6629
|
+
{ key: "surface", tr: "Kart / Yüzey (Surface)", en: "Surface" },
|
|
6630
|
+
{ key: "surfaceAlt", tr: "Alternatif Yüzey", en: "Surface Alt" },
|
|
6631
|
+
{ key: "background", tr: "Sayfa Arka Planı", en: "Background" },
|
|
6632
|
+
{ key: "textPrimary", tr: "Ana Metin Rengi", en: "Primary Text" },
|
|
6633
|
+
{ key: "textSecondary", tr: "İkincil Metin Rengi", en: "Secondary Text" },
|
|
6634
|
+
{ key: "border", tr: "Kenarlık (Border)", en: "Border" }
|
|
6635
|
+
];
|
|
6636
|
+
const DEFAULT_PALETTE_SEEDS = [
|
|
6637
|
+
{
|
|
6638
|
+
name: "Enterprise Indigo (Default)",
|
|
6639
|
+
slug: "enterprise-indigo",
|
|
6640
|
+
description: "Balanced Indigo, Sky Blue, and Dark Slate palette for modern SaaS & enterprise interfaces",
|
|
6641
|
+
isActive: true,
|
|
6642
|
+
rawSemantic: {
|
|
6643
|
+
primary: "#4f46e5",
|
|
6644
|
+
secondary: "#0ea5e9",
|
|
6645
|
+
accent: "#8b5cf6",
|
|
6646
|
+
success: "#10b981",
|
|
6647
|
+
warning: "#f59e0b",
|
|
6648
|
+
error: "#ef4444",
|
|
6649
|
+
info: "#3b82f6",
|
|
6650
|
+
surface: "#ffffff",
|
|
6651
|
+
surfaceAlt: "#f8fafc",
|
|
6652
|
+
background: "#f1f5f9",
|
|
6653
|
+
textPrimary: "#0f172a",
|
|
6654
|
+
textSecondary: "#475569",
|
|
6655
|
+
border: "#e2e8f0"
|
|
6656
|
+
},
|
|
6657
|
+
rawCustom: [
|
|
6658
|
+
{ key: "brandGold", value: "#d97706", labels: { tr: "Kurumsal Altın", en: "Brand Gold" } },
|
|
6659
|
+
{ key: "heroCyan", value: "rgb(6, 182, 212)", labels: { tr: "Vitrin Turkuaz (RGB)", en: "Hero Cyan (RGB)" } },
|
|
6660
|
+
{ key: "glassDark", value: "rgba(15, 23, 42, 0.76)", labels: { tr: "Koyu Cam Efekt (RGBA)", en: "Dark Glass Scrim (RGBA)" } },
|
|
6661
|
+
{ key: "coralHighlight", value: "#f43f5e", labels: { tr: "Mercan Vurgu", en: "Coral Highlight" } }
|
|
6662
|
+
]
|
|
6663
|
+
},
|
|
6664
|
+
{
|
|
6665
|
+
name: "Emerald Fintech & Sustainability",
|
|
6666
|
+
slug: "emerald-fintech",
|
|
6667
|
+
description: "Emerald Green & Ocean Navy palette crafted for fintech, energy, and sustainability platforms",
|
|
6668
|
+
isActive: false,
|
|
6669
|
+
rawSemantic: {
|
|
6670
|
+
primary: "#059669",
|
|
6671
|
+
secondary: "#0f766e",
|
|
6672
|
+
accent: "#0284c7",
|
|
6673
|
+
success: "#16a34a",
|
|
6674
|
+
warning: "#d97706",
|
|
6675
|
+
error: "#dc2626",
|
|
6676
|
+
info: "#0ea5e9",
|
|
6677
|
+
surface: "#ffffff",
|
|
6678
|
+
surfaceAlt: "#f0fdf4",
|
|
6679
|
+
background: "#f8fafc",
|
|
6680
|
+
textPrimary: "#064e3b",
|
|
6681
|
+
textSecondary: "#334155",
|
|
6682
|
+
border: "#d1fae5"
|
|
6683
|
+
},
|
|
6684
|
+
rawCustom: [
|
|
6685
|
+
{ key: "brandGold", value: "#ca8a04", labels: { tr: "Kurumsal Altın", en: "Brand Gold" } },
|
|
6686
|
+
{ key: "heroCyan", value: "rgb(20, 184, 166)", labels: { tr: "Mint Yeşil (RGB)", en: "Mint Teal (RGB)" } },
|
|
6687
|
+
{ key: "glassDark", value: "rgba(6, 78, 59, 0.78)", labels: { tr: "Zümrüt Cam (RGBA)", en: "Emerald Glass (RGBA)" } },
|
|
6688
|
+
{ key: "coralHighlight", value: "#ea580c", labels: { tr: "Sıcak Turuncu", en: "Warm Terracotta" } }
|
|
6689
|
+
]
|
|
6690
|
+
},
|
|
6691
|
+
{
|
|
6692
|
+
name: "Royal Amber & Executive Navy",
|
|
6693
|
+
slug: "royal-amber",
|
|
6694
|
+
description: "Executive Navy & Royal Amber Gold palette for corporate holdings, legal, real estate, and luxury brands",
|
|
6695
|
+
isActive: false,
|
|
6696
|
+
rawSemantic: {
|
|
6697
|
+
primary: "#1e3a8a",
|
|
6698
|
+
secondary: "#d97706",
|
|
6699
|
+
accent: "#b45309",
|
|
6700
|
+
success: "#15803d",
|
|
6701
|
+
warning: "#eab308",
|
|
6702
|
+
error: "#b91c1c",
|
|
6703
|
+
info: "#1d4ed8",
|
|
6704
|
+
surface: "#ffffff",
|
|
6705
|
+
surfaceAlt: "#fffbeb",
|
|
6706
|
+
background: "#f8fafc",
|
|
6707
|
+
textPrimary: "#0f172a",
|
|
6708
|
+
textSecondary: "#475569",
|
|
6709
|
+
border: "#e2e8f0"
|
|
6710
|
+
},
|
|
6711
|
+
rawCustom: [
|
|
6712
|
+
{ key: "brandGold", value: "#f59e0b", labels: { tr: "Kraliyet Altını", en: "Royal Gold" } },
|
|
6713
|
+
{ key: "heroCyan", value: "rgb(59, 130, 246)", labels: { tr: "Kraliyet Mavisi (RGB)", en: "Royal Blue (RGB)" } },
|
|
6714
|
+
{ key: "glassDark", value: "rgba(23, 37, 84, 0.82)", labels: { tr: "Lacivert Cam (RGBA)", en: "Navy Glass (RGBA)" } },
|
|
6715
|
+
{ key: "coralHighlight", value: "#e11d48", labels: { tr: "Yakut Vurgu", en: "Ruby Highlight" } }
|
|
6716
|
+
]
|
|
6717
|
+
},
|
|
6718
|
+
{
|
|
6719
|
+
name: "Crimson Editorial & Media",
|
|
6720
|
+
slug: "crimson-editorial",
|
|
6721
|
+
description: "High-energy Crimson & Violet palette for editorial media, e-commerce campaigns, and digital agencies",
|
|
6722
|
+
isActive: false,
|
|
6723
|
+
rawSemantic: {
|
|
6724
|
+
primary: "#e11d48",
|
|
6725
|
+
secondary: "#7c3aed",
|
|
6726
|
+
accent: "#f97316",
|
|
6727
|
+
success: "#10b981",
|
|
6728
|
+
warning: "#f59e0b",
|
|
6729
|
+
error: "#dc2626",
|
|
6730
|
+
info: "#6366f1",
|
|
6731
|
+
surface: "#ffffff",
|
|
6732
|
+
surfaceAlt: "#fff1f2",
|
|
6733
|
+
background: "#fafafa",
|
|
6734
|
+
textPrimary: "#18181b",
|
|
6735
|
+
textSecondary: "#52525b",
|
|
6736
|
+
border: "#e4e4e7"
|
|
6737
|
+
},
|
|
6738
|
+
rawCustom: [
|
|
6739
|
+
{ key: "brandGold", value: "#f97316", labels: { tr: "Kampanya Turuncusu", en: "Campaign Orange" } },
|
|
6740
|
+
{ key: "heroCyan", value: "rgb(168, 85, 247)", labels: { tr: "Neon Mor (RGB)", en: "Neon Purple (RGB)" } },
|
|
6741
|
+
{ key: "glassDark", value: "rgba(24, 24, 27, 0.80)", labels: { tr: "Antrasit Cam (RGBA)", en: "Charcoal Glass (RGBA)" } },
|
|
6742
|
+
{ key: "coralHighlight", value: "#f43f5e", labels: { tr: "Mercan Vurgu", en: "Coral Highlight" } }
|
|
6743
|
+
]
|
|
6744
|
+
}
|
|
6745
|
+
];
|
|
6746
|
+
function normalizePalettePayload(raw) {
|
|
6747
|
+
const semanticIn = raw?.semanticTokens && typeof raw.semanticTokens === "object" ? raw.semanticTokens : {};
|
|
6748
|
+
const semanticTokens = {};
|
|
6749
|
+
for (const meta of SEMANTIC_TOKEN_META) {
|
|
6750
|
+
const incoming = semanticIn[meta.key];
|
|
6751
|
+
const rawColor = typeof incoming === "string" ? incoming : incoming?.value || incoming?.hex || incoming?.rgb || "#4f46e5";
|
|
6752
|
+
semanticTokens[meta.key] = buildTokenEntry(
|
|
6753
|
+
rawColor,
|
|
6754
|
+
incoming?.labels || { tr: meta.tr, en: meta.en },
|
|
6755
|
+
{
|
|
6756
|
+
soft: incoming?.soft,
|
|
6757
|
+
contrast: incoming?.contrast
|
|
6758
|
+
}
|
|
6759
|
+
);
|
|
6760
|
+
}
|
|
6761
|
+
const customIn = Array.isArray(raw?.customTokens) ? raw.customTokens : [];
|
|
6762
|
+
const customTokens = customIn.filter((c) => c && typeof c.key === "string" && c.key.trim()).map((c) => {
|
|
6763
|
+
const cleanKey = String(c.key).trim().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
6764
|
+
const base = buildTokenEntry(
|
|
6765
|
+
c.value || c.hex || c.rgb || "#4f46e5",
|
|
6766
|
+
c.labels && typeof c.labels === "object" ? c.labels : { tr: cleanKey, en: cleanKey },
|
|
6767
|
+
{
|
|
6768
|
+
soft: c.soft,
|
|
6769
|
+
contrast: c.contrast
|
|
6770
|
+
}
|
|
6771
|
+
);
|
|
6772
|
+
return {
|
|
6773
|
+
key: cleanKey,
|
|
6774
|
+
...base,
|
|
6775
|
+
labels: c.labels && typeof c.labels === "object" ? c.labels : { tr: cleanKey, en: cleanKey }
|
|
6776
|
+
};
|
|
6777
|
+
});
|
|
6778
|
+
return {
|
|
6779
|
+
name: String(raw?.name || "Custom Theme Palette").trim(),
|
|
6780
|
+
slug: String(raw?.slug || raw?.name || "custom-palette").toLowerCase().replace(/[^a-z0-9-_]+/g, "-").replace(/^-+|-+$/g, "") || `palette-${Date.now()}`,
|
|
6781
|
+
description: String(raw?.description || "").trim(),
|
|
6782
|
+
isActive: Boolean(raw?.isActive),
|
|
6783
|
+
semanticTokens,
|
|
6784
|
+
customTokens
|
|
6785
|
+
};
|
|
6786
|
+
}
|
|
6787
|
+
function buildCssVariablesMap(palette) {
|
|
6788
|
+
const vars = {};
|
|
6789
|
+
if (!palette) return vars;
|
|
6790
|
+
const sem = palette.semanticTokens || {};
|
|
6791
|
+
for (const [key, entry] of Object.entries(sem)) {
|
|
6792
|
+
if (!entry) continue;
|
|
6793
|
+
const val = entry.value || entry.hex || "#4f46e5";
|
|
6794
|
+
vars[`--ci-color-${key}`] = val;
|
|
6795
|
+
if (entry.soft) vars[`--ci-color-${key}-soft`] = entry.soft;
|
|
6796
|
+
if (entry.contrast) vars[`--ci-color-${key}-contrast`] = entry.contrast;
|
|
6797
|
+
if (entry.hex) vars[`--ci-color-${key}-hex`] = entry.hex;
|
|
6798
|
+
if (entry.rgb) vars[`--ci-color-${key}-rgb`] = entry.rgb;
|
|
6799
|
+
}
|
|
6800
|
+
const cust = Array.isArray(palette.customTokens) ? palette.customTokens : [];
|
|
6801
|
+
for (const item of cust) {
|
|
6802
|
+
if (!item?.key) continue;
|
|
6803
|
+
const val = item.value || item.hex || "#4f46e5";
|
|
6804
|
+
vars[`--ci-color-${item.key}`] = val;
|
|
6805
|
+
if (item.soft) vars[`--ci-color-${item.key}-soft`] = item.soft;
|
|
6806
|
+
if (item.contrast) vars[`--ci-color-${item.key}-contrast`] = item.contrast;
|
|
6807
|
+
}
|
|
6808
|
+
return vars;
|
|
6809
|
+
}
|
|
6810
|
+
const ciColorService = ({ strapi }) => ({
|
|
6811
|
+
async ensureSeeded() {
|
|
6812
|
+
const existing = await strapi.db.query(PALETTE_UID).findMany({ limit: 50 });
|
|
6813
|
+
if (Array.isArray(existing) && existing.length > 0) {
|
|
6814
|
+
const hasActive = existing.some((p) => p.isActive);
|
|
6815
|
+
if (!hasActive && existing[0]?.id) {
|
|
6816
|
+
await strapi.db.query(PALETTE_UID).update({
|
|
6817
|
+
where: { id: existing[0].id },
|
|
6818
|
+
data: { isActive: true }
|
|
6819
|
+
});
|
|
6820
|
+
}
|
|
6821
|
+
return;
|
|
6822
|
+
}
|
|
6823
|
+
for (const seed of DEFAULT_PALETTE_SEEDS) {
|
|
6824
|
+
const semanticTokens = {};
|
|
6825
|
+
for (const meta of SEMANTIC_TOKEN_META) {
|
|
6826
|
+
const rawHex = seed.rawSemantic[meta.key] || "#4f46e5";
|
|
6827
|
+
semanticTokens[meta.key] = buildTokenEntry(rawHex, { tr: meta.tr, en: meta.en });
|
|
6828
|
+
}
|
|
6829
|
+
const customTokens = seed.rawCustom.map((c) => ({
|
|
6830
|
+
key: c.key,
|
|
6831
|
+
...buildTokenEntry(c.value, c.labels),
|
|
6832
|
+
labels: c.labels
|
|
6833
|
+
}));
|
|
6834
|
+
await strapi.db.query(PALETTE_UID).create({
|
|
6835
|
+
data: {
|
|
6836
|
+
name: seed.name,
|
|
6837
|
+
slug: seed.slug,
|
|
6838
|
+
description: seed.description,
|
|
6839
|
+
isActive: seed.isActive,
|
|
6840
|
+
semanticTokens,
|
|
6841
|
+
customTokens
|
|
6842
|
+
}
|
|
6843
|
+
});
|
|
6844
|
+
}
|
|
6845
|
+
},
|
|
6846
|
+
async findAll() {
|
|
6847
|
+
await this.ensureSeeded();
|
|
6848
|
+
const palettes = await strapi.db.query(PALETTE_UID).findMany({
|
|
6849
|
+
orderBy: { id: "asc" }
|
|
6850
|
+
});
|
|
6851
|
+
const active = palettes.find((p) => p.isActive) || palettes[0] || null;
|
|
6852
|
+
return {
|
|
6853
|
+
data: palettes,
|
|
6854
|
+
active,
|
|
6855
|
+
cssVariables: buildCssVariablesMap(active)
|
|
6856
|
+
};
|
|
6857
|
+
},
|
|
6858
|
+
async findActivePublic(slugOverride) {
|
|
6859
|
+
await this.ensureSeeded();
|
|
6860
|
+
const allPalettes = await strapi.db.query(PALETTE_UID).findMany({
|
|
6861
|
+
orderBy: { id: "asc" }
|
|
6862
|
+
});
|
|
6863
|
+
let palette = null;
|
|
6864
|
+
if (slugOverride) {
|
|
6865
|
+
palette = allPalettes.find((p) => p.slug === slugOverride) || null;
|
|
6866
|
+
}
|
|
6867
|
+
if (!palette) {
|
|
6868
|
+
palette = allPalettes.find((p) => p.isActive) || allPalettes[0] || null;
|
|
6869
|
+
}
|
|
6870
|
+
return {
|
|
6871
|
+
data: palette,
|
|
6872
|
+
palette,
|
|
6873
|
+
palettes: allPalettes.map((p) => ({
|
|
6874
|
+
name: p.name,
|
|
6875
|
+
slug: p.slug,
|
|
6876
|
+
isActive: Boolean(p.isActive),
|
|
6877
|
+
primary: p.semanticTokens?.primary?.value || p.semanticTokens?.primary?.hex || "#4f46e5",
|
|
6878
|
+
secondary: p.semanticTokens?.secondary?.value || p.semanticTokens?.secondary?.hex || "#0ea5e9",
|
|
6879
|
+
accent: p.semanticTokens?.accent?.value || p.semanticTokens?.accent?.hex || "#f59e0b"
|
|
6880
|
+
})),
|
|
6881
|
+
cssVariables: buildCssVariablesMap(palette)
|
|
6882
|
+
};
|
|
6883
|
+
},
|
|
6884
|
+
async save(payload) {
|
|
6885
|
+
await this.ensureSeeded();
|
|
6886
|
+
const normalized = normalizePalettePayload(payload);
|
|
6887
|
+
let existing = null;
|
|
6888
|
+
if (payload?.id) {
|
|
6889
|
+
existing = await strapi.db.query(PALETTE_UID).findOne({ where: { id: Number(payload.id) } });
|
|
6890
|
+
}
|
|
6891
|
+
if (!existing && payload?.documentId) {
|
|
6892
|
+
existing = await strapi.db.query(PALETTE_UID).findOne({ where: { documentId: payload.documentId } });
|
|
6893
|
+
}
|
|
6894
|
+
if (!existing && normalized.slug) {
|
|
6895
|
+
existing = await strapi.db.query(PALETTE_UID).findOne({ where: { slug: normalized.slug } });
|
|
6896
|
+
}
|
|
6897
|
+
if (normalized.isActive) {
|
|
6898
|
+
await strapi.db.query(PALETTE_UID).updateMany({
|
|
6899
|
+
where: { isActive: true },
|
|
6900
|
+
data: { isActive: false }
|
|
6901
|
+
});
|
|
6902
|
+
}
|
|
6903
|
+
let saved;
|
|
6904
|
+
if (existing) {
|
|
6905
|
+
saved = await strapi.db.query(PALETTE_UID).update({
|
|
6906
|
+
where: { id: existing.id },
|
|
6907
|
+
data: {
|
|
6908
|
+
...normalized,
|
|
6909
|
+
isActive: normalized.isActive || existing.isActive
|
|
6910
|
+
}
|
|
6911
|
+
});
|
|
6912
|
+
} else {
|
|
6913
|
+
saved = await strapi.db.query(PALETTE_UID).create({
|
|
6914
|
+
data: normalized
|
|
6915
|
+
});
|
|
6916
|
+
}
|
|
6917
|
+
return this.findAll().then((res) => ({
|
|
6918
|
+
...res,
|
|
6919
|
+
saved
|
|
6920
|
+
}));
|
|
6921
|
+
},
|
|
6922
|
+
async activate(idOrSlug) {
|
|
6923
|
+
await this.ensureSeeded();
|
|
6924
|
+
const str = String(idOrSlug).trim();
|
|
6925
|
+
let target = null;
|
|
6926
|
+
if (/^\d+$/.test(str)) {
|
|
6927
|
+
target = await strapi.db.query(PALETTE_UID).findOne({ where: { id: Number(str) } });
|
|
6928
|
+
}
|
|
6929
|
+
if (!target) {
|
|
6930
|
+
target = await strapi.db.query(PALETTE_UID).findOne({
|
|
6931
|
+
where: { $or: [{ slug: str }, { documentId: str }] }
|
|
6932
|
+
});
|
|
6933
|
+
}
|
|
6934
|
+
if (!target) return null;
|
|
6935
|
+
await strapi.db.query(PALETTE_UID).updateMany({
|
|
6936
|
+
where: { isActive: true },
|
|
6937
|
+
data: { isActive: false }
|
|
6938
|
+
});
|
|
6939
|
+
await strapi.db.query(PALETTE_UID).update({
|
|
6940
|
+
where: { id: target.id },
|
|
6941
|
+
data: { isActive: true }
|
|
6942
|
+
});
|
|
6943
|
+
return this.findAll();
|
|
6944
|
+
},
|
|
6945
|
+
async upsertQuickCustomToken(input) {
|
|
6946
|
+
await this.ensureSeeded();
|
|
6947
|
+
const { active } = await this.findActivePublic().then((r) => ({ active: r.data }));
|
|
6948
|
+
if (!active) return null;
|
|
6949
|
+
const cleanKey = String(input.key || input.label || "customColor").trim().replace(/[^a-zA-Z0-9_-]/g, "") || `color_${Date.now()}`;
|
|
6950
|
+
const labelStr = String(input.label || cleanKey).trim();
|
|
6951
|
+
const labels = input.labels && typeof input.labels === "object" ? input.labels : { tr: labelStr, en: labelStr };
|
|
6952
|
+
const tokenEntry = {
|
|
6953
|
+
key: cleanKey,
|
|
6954
|
+
...buildTokenEntry(input.value, labels),
|
|
6955
|
+
labels
|
|
6956
|
+
};
|
|
6957
|
+
const prevCustom = Array.isArray(active.customTokens) ? [...active.customTokens] : [];
|
|
6958
|
+
const idx = prevCustom.findIndex((t) => t.key === cleanKey);
|
|
6959
|
+
if (idx >= 0) {
|
|
6960
|
+
prevCustom[idx] = tokenEntry;
|
|
6961
|
+
} else {
|
|
6962
|
+
prevCustom.push(tokenEntry);
|
|
6963
|
+
}
|
|
6964
|
+
await strapi.db.query(PALETTE_UID).update({
|
|
6965
|
+
where: { id: active.id },
|
|
6966
|
+
data: { customTokens: prevCustom }
|
|
6967
|
+
});
|
|
6968
|
+
return {
|
|
6969
|
+
...await this.findAll(),
|
|
6970
|
+
addedToken: tokenEntry
|
|
6971
|
+
};
|
|
6972
|
+
},
|
|
6973
|
+
async remove(idOrSlug) {
|
|
6974
|
+
const str = String(idOrSlug).trim();
|
|
6975
|
+
const all = await strapi.db.query(PALETTE_UID).findMany();
|
|
6976
|
+
if (all.length <= 1) {
|
|
6977
|
+
throw new Error("Cannot delete the last remaining color palette");
|
|
6978
|
+
}
|
|
6979
|
+
const target = all.find(
|
|
6980
|
+
(p) => String(p.id) === str || p.slug === str || p.documentId === str
|
|
6981
|
+
);
|
|
6982
|
+
if (!target) return this.findAll();
|
|
6983
|
+
await strapi.db.query(PALETTE_UID).delete({ where: { id: target.id } });
|
|
6984
|
+
if (target.isActive) {
|
|
6985
|
+
const remaining = await strapi.db.query(PALETTE_UID).findMany({ limit: 1 });
|
|
6986
|
+
if (remaining[0]) {
|
|
6987
|
+
await strapi.db.query(PALETTE_UID).update({
|
|
6988
|
+
where: { id: remaining[0].id },
|
|
6989
|
+
data: { isActive: true }
|
|
6990
|
+
});
|
|
6991
|
+
}
|
|
6992
|
+
}
|
|
6993
|
+
return this.findAll();
|
|
6994
|
+
},
|
|
6995
|
+
/**
|
|
6996
|
+
* Safe public collection query for Data Table (`sourceMode: 'strapi_collection'`)
|
|
6997
|
+
*/
|
|
6998
|
+
async queryCollectionForDataTable(params) {
|
|
6999
|
+
const uid = String(params.uid || "").trim();
|
|
7000
|
+
if (!uid.startsWith("api::")) {
|
|
7001
|
+
return { columns: [], rows: [] };
|
|
7002
|
+
}
|
|
7003
|
+
const ct = strapi.contentTypes[uid];
|
|
7004
|
+
if (!ct) {
|
|
7005
|
+
return { columns: [], rows: [] };
|
|
7006
|
+
}
|
|
7007
|
+
const attrs = ct.attributes || {};
|
|
7008
|
+
const forbiddenTypes = /* @__PURE__ */ new Set(["password", "dynamiczone", "component", "relation"]);
|
|
7009
|
+
const allowedFields = [
|
|
7010
|
+
{ key: "documentId", type: "text" }
|
|
7011
|
+
];
|
|
7012
|
+
for (const [fieldName, attr] of Object.entries(attrs)) {
|
|
7013
|
+
if (!attr || attr.private) continue;
|
|
7014
|
+
if (/password|secret|token|hash/i.test(fieldName)) continue;
|
|
7015
|
+
if (attr.customField === "plugin::content-input.content-input") continue;
|
|
7016
|
+
if (forbiddenTypes.has(attr.type)) continue;
|
|
7017
|
+
allowedFields.push({ key: fieldName, type: attr.type || "string" });
|
|
7018
|
+
}
|
|
7019
|
+
for (const sysKey of ["createdAt", "updatedAt", "publishedAt"]) {
|
|
7020
|
+
if (!allowedFields.some((f) => f.key === sysKey)) {
|
|
7021
|
+
allowedFields.push({ key: sysKey, type: "datetime" });
|
|
7022
|
+
}
|
|
7023
|
+
}
|
|
7024
|
+
if (!allowedFields.some((f) => f.key === "collectionLabel")) {
|
|
7025
|
+
allowedFields.push({ key: "collectionLabel", type: "enumeration" });
|
|
7026
|
+
}
|
|
7027
|
+
if (attrs.slug && !allowedFields.some((f) => f.key === "url")) {
|
|
7028
|
+
allowedFields.push({ key: "url", type: "uid" });
|
|
7029
|
+
}
|
|
7030
|
+
const limit = clamp(Number(params.limit) || 25, 1, 100);
|
|
7031
|
+
let entries = [];
|
|
7032
|
+
try {
|
|
7033
|
+
const docService = strapi.documents?.(uid);
|
|
7034
|
+
if (docService) {
|
|
7035
|
+
entries = await docService.findMany({
|
|
7036
|
+
status: "published",
|
|
7037
|
+
limit,
|
|
7038
|
+
sort: params.sort || "createdAt:desc",
|
|
7039
|
+
populate: "*"
|
|
7040
|
+
});
|
|
7041
|
+
if (!entries.length) {
|
|
7042
|
+
entries = await docService.findMany({
|
|
7043
|
+
limit,
|
|
7044
|
+
sort: params.sort || "createdAt:desc",
|
|
7045
|
+
populate: "*"
|
|
7046
|
+
});
|
|
7047
|
+
}
|
|
7048
|
+
} else {
|
|
7049
|
+
entries = await strapi.db.query(uid).findMany({ limit, populate: true });
|
|
7050
|
+
}
|
|
7051
|
+
} catch {
|
|
7052
|
+
entries = [];
|
|
7053
|
+
}
|
|
7054
|
+
const collectionLabelText = ct.info?.displayName || uid;
|
|
7055
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
7056
|
+
const sanitizedRows = await Promise.all(
|
|
7057
|
+
(entries || []).map(async (entry) => {
|
|
7058
|
+
const row = {};
|
|
7059
|
+
for (const f of allowedFields) {
|
|
7060
|
+
if (f.key === "collectionLabel" && entry.collectionLabel === void 0) {
|
|
7061
|
+
row.collectionLabel = collectionLabelText;
|
|
7062
|
+
continue;
|
|
7063
|
+
}
|
|
7064
|
+
if (f.key === "url" && entry.url === void 0) {
|
|
7065
|
+
const slugStr = entry.slug ? String(entry.slug).trim() : "";
|
|
7066
|
+
row.url = slugStr ? slugStr === "home" ? "/" : `/${slugStr.replace(/^\/+/, "")}` : "";
|
|
7067
|
+
continue;
|
|
7068
|
+
}
|
|
7069
|
+
const val = entry[f.key];
|
|
7070
|
+
if (val !== null && val !== void 0 && typeof val === "object") {
|
|
7071
|
+
if (Array.isArray(val)) {
|
|
7072
|
+
if (val[0]?.url) {
|
|
7073
|
+
const enriched = await enrichMediaAssetNode(strapi, val[0], {
|
|
7074
|
+
defaultAutoMaxW: 800,
|
|
7075
|
+
fileCache
|
|
7076
|
+
});
|
|
7077
|
+
row[f.key] = enriched?.optimized_url || enriched?.url || val[0].url;
|
|
7078
|
+
} else {
|
|
7079
|
+
row[f.key] = `${val.length} item`;
|
|
7080
|
+
}
|
|
7081
|
+
} else if (val.url) {
|
|
7082
|
+
const enriched = await enrichMediaAssetNode(strapi, val, {
|
|
7083
|
+
defaultAutoMaxW: 800,
|
|
7084
|
+
fileCache
|
|
7085
|
+
});
|
|
7086
|
+
row[f.key] = enriched?.optimized_url || enriched?.url || val.url;
|
|
7087
|
+
} else {
|
|
7088
|
+
row[f.key] = "";
|
|
7089
|
+
}
|
|
7090
|
+
} else {
|
|
7091
|
+
row[f.key] = val ?? "";
|
|
7092
|
+
}
|
|
7093
|
+
}
|
|
7094
|
+
return row;
|
|
7095
|
+
})
|
|
7096
|
+
);
|
|
7097
|
+
return {
|
|
7098
|
+
uid,
|
|
7099
|
+
displayName: ct.info?.displayName || uid,
|
|
7100
|
+
availableFields: allowedFields,
|
|
7101
|
+
rows: sanitizedRows
|
|
7102
|
+
};
|
|
7103
|
+
},
|
|
7104
|
+
/**
|
|
7105
|
+
* Batch Entity Cards resolver for `entityCard` Swiper Carousel & Grid modes
|
|
7106
|
+
*/
|
|
7107
|
+
async resolveEntityCardsBatch(params) {
|
|
7108
|
+
const uid = String(params.uid || "api::page.page").trim();
|
|
7109
|
+
if (!uid.startsWith("api::")) return [];
|
|
7110
|
+
const formSvc = strapi.plugin("content-input").service("ci-form");
|
|
7111
|
+
const docIds = Array.isArray(params.documentIds) ? params.documentIds.map((s) => String(s).trim()).filter(Boolean) : [];
|
|
7112
|
+
if (docIds.length > 0) {
|
|
7113
|
+
const results = await Promise.all(
|
|
7114
|
+
docIds.map(
|
|
7115
|
+
(documentId) => formSvc.resolveEntityCard({ uid, documentId }).catch(() => null)
|
|
7116
|
+
)
|
|
7117
|
+
);
|
|
7118
|
+
return results.filter(Boolean);
|
|
7119
|
+
}
|
|
7120
|
+
const limit = clamp(Number(params.limit) || 6, 1, 24);
|
|
7121
|
+
try {
|
|
7122
|
+
const docService = strapi.documents?.(uid);
|
|
7123
|
+
let entries = [];
|
|
7124
|
+
if (docService) {
|
|
7125
|
+
entries = await docService.findMany({ status: "published", limit, sort: "createdAt:desc" });
|
|
7126
|
+
if (!entries.length) {
|
|
7127
|
+
entries = await docService.findMany({ limit, sort: "createdAt:desc" });
|
|
7128
|
+
}
|
|
7129
|
+
} else {
|
|
7130
|
+
entries = await strapi.db.query(uid).findMany({ limit });
|
|
7131
|
+
}
|
|
7132
|
+
const uniqueDocIds = Array.from(
|
|
7133
|
+
new Set(entries.map((e) => e.documentId).filter(Boolean))
|
|
7134
|
+
);
|
|
7135
|
+
const cards = await Promise.all(
|
|
7136
|
+
uniqueDocIds.slice(0, limit).map(
|
|
7137
|
+
(documentId) => formSvc.resolveEntityCard({ uid, documentId }).catch(() => null)
|
|
7138
|
+
)
|
|
7139
|
+
);
|
|
7140
|
+
return cards.filter(Boolean);
|
|
7141
|
+
} catch {
|
|
7142
|
+
return [];
|
|
7143
|
+
}
|
|
7144
|
+
}
|
|
7145
|
+
});
|
|
5271
7146
|
const services = {
|
|
5272
7147
|
"ci-template": ciTemplateService,
|
|
5273
7148
|
"ci-menu": ciMenuService,
|
|
5274
7149
|
"ci-form": ciFormService,
|
|
5275
|
-
"ci-survey": ciSurveyService
|
|
7150
|
+
"ci-survey": ciSurveyService,
|
|
7151
|
+
"ci-color": ciColorService
|
|
5276
7152
|
};
|
|
5277
7153
|
const index = {
|
|
5278
7154
|
register,
|