@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.mjs
CHANGED
|
@@ -13,31 +13,987 @@ const register = ({ strapi }) => {
|
|
|
13
13
|
isResizable: false
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
+
if (strapi?.server?.use) {
|
|
17
|
+
strapi.server.use(async (ctx, next) => {
|
|
18
|
+
await next();
|
|
19
|
+
const csp = ctx?.response?.get?.("Content-Security-Policy");
|
|
20
|
+
if (typeof csp === "string" && csp.includes("frame-src")) {
|
|
21
|
+
const updated = csp.replace(/frame-src\s+([^;]+)/i, (match, sources) => {
|
|
22
|
+
if (sources.includes("https:") || sources.includes("*")) return match;
|
|
23
|
+
return `frame-src ${sources.trim()} https: http: data: blob:`;
|
|
24
|
+
});
|
|
25
|
+
if (updated !== csp) {
|
|
26
|
+
ctx.set("Content-Security-Policy", updated);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
16
31
|
};
|
|
32
|
+
const inFlightVariants = /* @__PURE__ */ new Map();
|
|
33
|
+
function getSharp() {
|
|
34
|
+
const req = typeof require !== "undefined" ? require : createRequire(path.join(process.cwd(), "package.json"));
|
|
35
|
+
return req("sharp");
|
|
36
|
+
}
|
|
37
|
+
function getVariantConfig(strapi) {
|
|
38
|
+
const pluginCfg = strapi?.config?.get?.("plugin::content-input") || {};
|
|
39
|
+
const envFolder = process.env.CI_IMAGE_VARIANT_FOLDER;
|
|
40
|
+
const rawFolder = envFolder !== void 0 && String(envFolder).trim() !== "" ? String(envFolder).trim() : pluginCfg.imageVariantFolder !== void 0 ? pluginCfg.imageVariantFolder : "ci-optimized";
|
|
41
|
+
let folder = "ci-optimized";
|
|
42
|
+
if (rawFolder === null || rawFolder === false || String(rawFolder).trim().toLowerCase() === "none" || String(rawFolder).trim() === "/") {
|
|
43
|
+
folder = null;
|
|
44
|
+
} else {
|
|
45
|
+
const cleaned = String(rawFolder).trim().replace(/^\/+|\/+$/g, "");
|
|
46
|
+
folder = cleaned || "ci-optimized";
|
|
47
|
+
}
|
|
48
|
+
const rawFmt = String(
|
|
49
|
+
process.env.CI_IMAGE_VARIANT_FORMAT || pluginCfg.imageVariantFormat || "webp"
|
|
50
|
+
).trim().toLowerCase();
|
|
51
|
+
const defaultFormat = rawFmt === "auto" ? "auto" : "webp";
|
|
52
|
+
const envRedirect = process.env.CI_IMAGE_REDIRECT_CDN;
|
|
53
|
+
const redirectProxyToCdn = envRedirect !== void 0 ? envRedirect !== "0" && envRedirect.toLowerCase() !== "false" : pluginCfg.redirectProxyToCdn !== false;
|
|
54
|
+
const defaultQuality = Math.min(
|
|
55
|
+
100,
|
|
56
|
+
Math.max(40, Number(pluginCfg.imageVariantQuality) || 85)
|
|
57
|
+
);
|
|
58
|
+
return {
|
|
59
|
+
folder,
|
|
60
|
+
defaultFormat,
|
|
61
|
+
redirectProxyToCdn,
|
|
62
|
+
defaultQuality
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function isAbsoluteHttpUrl(url) {
|
|
66
|
+
return Boolean(url && /^https?:\/\//i.test(String(url).trim()));
|
|
67
|
+
}
|
|
68
|
+
function isOptimizableRasterImage(mime, urlOrName) {
|
|
69
|
+
const m = String(mime || "").trim().toLowerCase();
|
|
70
|
+
const u = String(urlOrName || "").split("?")[0].split("#")[0].trim().toLowerCase();
|
|
71
|
+
if (u.startsWith("data:") || u.startsWith("blob:")) return false;
|
|
72
|
+
if (m.includes("svg") || m.includes("gif") || m.startsWith("video/") || m.startsWith("audio/") || m.startsWith("application/") || m.startsWith("text/")) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if (/\.(svg|gif|mp4|webm|mov|m4v|mp3|wav|ogg|pdf|docx?|xlsx?|pptx?|zip|rar)$/i.test(u)) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (m === "image/jpeg" || m === "image/jpg" || m === "image/png" || m === "image/webp" || m === "image/avif" || m === "image/tiff" || m === "image/bmp") {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (/\.(jpe?g|png|webp|avif|tiff?|bmp)$/i.test(u)) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
if (m.startsWith("image/")) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
async function loadSourceBuffer(strapi, src) {
|
|
90
|
+
const publicDir = strapi?.dirs?.static?.public || path.join(process.cwd(), "public");
|
|
91
|
+
if (src.startsWith("/")) {
|
|
92
|
+
const cleanRel = decodeURIComponent(src.split("?")[0]).replace(/^\/+/, "");
|
|
93
|
+
const fullPath = path.resolve(publicDir, cleanRel);
|
|
94
|
+
const resolvedPublic = path.resolve(publicDir);
|
|
95
|
+
if (!fullPath.startsWith(resolvedPublic)) {
|
|
96
|
+
throw new Error("Invalid local file path");
|
|
97
|
+
}
|
|
98
|
+
if (!fs.existsSync(fullPath)) {
|
|
99
|
+
throw new Error(`File not found: ${src}`);
|
|
100
|
+
}
|
|
101
|
+
const buffer = await fs.promises.readFile(fullPath);
|
|
102
|
+
const ext = path.extname(fullPath).toLowerCase();
|
|
103
|
+
const mime = ext === ".png" ? "image/png" : ext === ".webp" ? "image/webp" : ext === ".avif" ? "image/avif" : ext === ".gif" ? "image/gif" : "image/jpeg";
|
|
104
|
+
return { buffer, mime };
|
|
105
|
+
}
|
|
106
|
+
if (/^https?:\/\//i.test(src)) {
|
|
107
|
+
const parsed = new URL(src);
|
|
108
|
+
if ((parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1") && parsed.pathname.startsWith("/uploads/")) {
|
|
109
|
+
const cleanRel = decodeURIComponent(parsed.pathname).replace(/^\/+/, "");
|
|
110
|
+
const fullPath = path.resolve(publicDir, cleanRel);
|
|
111
|
+
if (fs.existsSync(fullPath)) {
|
|
112
|
+
const buffer = await fs.promises.readFile(fullPath);
|
|
113
|
+
const ext = path.extname(fullPath).toLowerCase();
|
|
114
|
+
const mime = ext === ".png" ? "image/png" : ext === ".webp" ? "image/webp" : "image/jpeg";
|
|
115
|
+
return { buffer, mime };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const res = await fetch(src);
|
|
119
|
+
if (!res.ok) {
|
|
120
|
+
throw new Error(`Failed to fetch remote image (${res.status})`);
|
|
121
|
+
}
|
|
122
|
+
const contentType = res.headers.get("content-type") || "image/jpeg";
|
|
123
|
+
const arr = await res.arrayBuffer();
|
|
124
|
+
return { buffer: Buffer.from(arr), mime: contentType };
|
|
125
|
+
}
|
|
126
|
+
throw new Error("Unsupported image source URL");
|
|
127
|
+
}
|
|
128
|
+
function normalizeImageProcessSpec(imageSettings, defaultAutoMaxW = 1920) {
|
|
129
|
+
const safeMaxW = Math.min(3840, Math.max(64, Math.round(Number(defaultAutoMaxW) || 1920)));
|
|
130
|
+
const rawProc = String(imageSettings?.process ?? "").trim().toLowerCase();
|
|
131
|
+
const rotate = parseInt(String(imageSettings?.rotate || "0"), 10) || 0;
|
|
132
|
+
const q = Math.min(100, Math.max(30, parseInt(String(imageSettings?.quality || "85"), 10) || 85));
|
|
133
|
+
if (rawProc === "none" || rawProc === "no-process" || rawProc === "original") {
|
|
134
|
+
return {
|
|
135
|
+
processMode: "none",
|
|
136
|
+
w: 0,
|
|
137
|
+
h: 0,
|
|
138
|
+
maxW: safeMaxW,
|
|
139
|
+
q,
|
|
140
|
+
rotate: 0
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (rawProc === "fit") {
|
|
144
|
+
const w = Math.min(3840, Math.max(0, Math.round(Number(imageSettings?.cWidth) || 0)));
|
|
145
|
+
const h = Math.min(3840, Math.max(0, Math.round(Number(imageSettings?.cHeight) || 0)));
|
|
146
|
+
if (w > 0 && h > 0) {
|
|
147
|
+
return { processMode: "fit", w, h, maxW: safeMaxW, q, rotate };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (rawProc === "widen") {
|
|
151
|
+
const w = Math.min(3840, Math.max(0, Math.round(Number(imageSettings?.cWidth) || 0)));
|
|
152
|
+
if (w > 0) {
|
|
153
|
+
return { processMode: "widen", w, h: 0, maxW: safeMaxW, q, rotate };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const customAutoW = Number(imageSettings?.maxWidth || imageSettings?.cWidth);
|
|
157
|
+
const autoW = rawProc === "auto" && customAutoW > 0 ? Math.min(3840, Math.max(64, Math.round(customAutoW))) : safeMaxW;
|
|
158
|
+
return {
|
|
159
|
+
processMode: "auto",
|
|
160
|
+
w: autoW,
|
|
161
|
+
h: 0,
|
|
162
|
+
maxW: autoW,
|
|
163
|
+
q,
|
|
164
|
+
rotate
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function computeCiFormatKey(processMode, w, h, rotate = 0) {
|
|
168
|
+
const effH = processMode === "fit" ? h : 0;
|
|
169
|
+
const effW = w;
|
|
170
|
+
return `ci_${processMode}_${effW}x${effH}${rotate ? `_r${rotate}` : ""}`;
|
|
171
|
+
}
|
|
172
|
+
function compactAssetFormats(formats) {
|
|
173
|
+
if (!formats || typeof formats !== "object") return void 0;
|
|
174
|
+
const out = {};
|
|
175
|
+
const keepStandard = /* @__PURE__ */ new Set(["thumbnail", "small", "medium", "large"]);
|
|
176
|
+
for (const [key, val] of Object.entries(formats)) {
|
|
177
|
+
if (!val || typeof val !== "object" || typeof val.url !== "string" || !val.url) continue;
|
|
178
|
+
if (!keepStandard.has(key) && !key.startsWith("ci_")) continue;
|
|
179
|
+
out[key] = {
|
|
180
|
+
url: val.url,
|
|
181
|
+
...val.width ? { width: Number(val.width) } : {},
|
|
182
|
+
...val.height ? { height: Number(val.height) } : {},
|
|
183
|
+
...val.mime ? { mime: String(val.mime) } : {},
|
|
184
|
+
...val.size ? { size: Number(val.size) } : {}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
188
|
+
}
|
|
189
|
+
function stripVariantPrefixFromHash(baseNameNoExt) {
|
|
190
|
+
return baseNameNoExt.replace(/^ci_(?:fit|widen|auto)_\d+x\d+(?:_r-?\d+)?_/, "");
|
|
191
|
+
}
|
|
192
|
+
async function findUploadFileForAsset(strapi, assetOrUrl, cache) {
|
|
193
|
+
if (!assetOrUrl) return null;
|
|
194
|
+
const fileQuery = strapi.db.query("plugin::upload.file");
|
|
195
|
+
const isObj = typeof assetOrUrl === "object";
|
|
196
|
+
const rawId = isObj ? assetOrUrl.id : void 0;
|
|
197
|
+
const rawHash = isObj ? assetOrUrl.hash : void 0;
|
|
198
|
+
const rawUrl = isObj ? assetOrUrl.original_url || assetOrUrl.url || assetOrUrl.target_url || assetOrUrl.src || "" : String(assetOrUrl || "");
|
|
199
|
+
const cleanUrl = String(rawUrl || "").split("?")[0].split("#")[0].trim();
|
|
200
|
+
const cacheKey = rawId ? `id:${rawId}` : rawHash ? `hash:${rawHash}` : cleanUrl ? `url:${cleanUrl}` : "";
|
|
201
|
+
if (cache && cacheKey && cache.has(cacheKey)) {
|
|
202
|
+
return cache.get(cacheKey);
|
|
203
|
+
}
|
|
204
|
+
let found = null;
|
|
205
|
+
const remember = (record) => {
|
|
206
|
+
if (cache) {
|
|
207
|
+
if (cacheKey) cache.set(cacheKey, record);
|
|
208
|
+
if (record?.id) cache.set(`id:${record.id}`, record);
|
|
209
|
+
if (record?.hash) cache.set(`hash:${record.hash}`, record);
|
|
210
|
+
if (record?.url) cache.set(`url:${String(record.url).split("?")[0]}`, record);
|
|
211
|
+
}
|
|
212
|
+
return record;
|
|
213
|
+
};
|
|
214
|
+
if (rawId !== void 0 && rawId !== null && rawId !== "") {
|
|
215
|
+
const numId = Number(rawId);
|
|
216
|
+
if (!Number.isNaN(numId) && numId > 0) {
|
|
217
|
+
found = await fileQuery.findOne({ where: { id: numId } });
|
|
218
|
+
if (found) return remember(found);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (rawHash && typeof rawHash === "string") {
|
|
222
|
+
const parentHash = stripVariantPrefixFromHash(rawHash.trim());
|
|
223
|
+
found = await fileQuery.findOne({ where: { hash: parentHash } });
|
|
224
|
+
if (found) return remember(found);
|
|
225
|
+
}
|
|
226
|
+
if (!cleanUrl) return remember(null);
|
|
227
|
+
found = await fileQuery.findOne({ where: { url: cleanUrl } });
|
|
228
|
+
if (found) return remember(found);
|
|
229
|
+
let pathnameStr = cleanUrl;
|
|
230
|
+
if (/^https?:\/\//i.test(cleanUrl)) {
|
|
231
|
+
try {
|
|
232
|
+
pathnameStr = decodeURIComponent(new URL(cleanUrl).pathname);
|
|
233
|
+
} catch {
|
|
234
|
+
pathnameStr = cleanUrl;
|
|
235
|
+
}
|
|
236
|
+
if (pathnameStr && pathnameStr !== cleanUrl) {
|
|
237
|
+
found = await fileQuery.findOne({ where: { url: pathnameStr } });
|
|
238
|
+
if (found) return remember(found);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const baseName = path.posix.basename(pathnameStr);
|
|
242
|
+
const ext = path.posix.extname(baseName);
|
|
243
|
+
const baseNoExt = ext ? baseName.slice(0, -ext.length) : baseName;
|
|
244
|
+
if (baseNoExt) {
|
|
245
|
+
const candidateHash = stripVariantPrefixFromHash(baseNoExt);
|
|
246
|
+
if (candidateHash) {
|
|
247
|
+
found = await fileQuery.findOne({ where: { hash: candidateHash } });
|
|
248
|
+
if (found) return remember(found);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return remember(null);
|
|
252
|
+
}
|
|
253
|
+
async function renderSharpVariantBuffer(sourceBuffer, sourceMime, opts) {
|
|
254
|
+
const sharp = getSharp();
|
|
255
|
+
let pipeline = sharp(sourceBuffer, { failOn: "none" }).rotate();
|
|
256
|
+
const rotate = opts.rotate || 0;
|
|
257
|
+
if (rotate && [90, 180, 270, -90].includes(rotate)) {
|
|
258
|
+
pipeline = pipeline.rotate(rotate);
|
|
259
|
+
}
|
|
260
|
+
const cw = opts.cw || 0;
|
|
261
|
+
const ch = opts.ch || 0;
|
|
262
|
+
if (cw > 0 && ch > 0) {
|
|
263
|
+
pipeline = pipeline.extract({
|
|
264
|
+
left: Math.max(0, opts.cx || 0),
|
|
265
|
+
top: Math.max(0, opts.cy || 0),
|
|
266
|
+
width: cw,
|
|
267
|
+
height: ch
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
const { processMode, w, h, q } = opts;
|
|
271
|
+
if (processMode === "fit" && w > 0 && h > 0) {
|
|
272
|
+
pipeline = pipeline.resize(w, h, {
|
|
273
|
+
fit: "cover",
|
|
274
|
+
position: "centre",
|
|
275
|
+
withoutEnlargement: false
|
|
276
|
+
});
|
|
277
|
+
} else if (processMode === "widen" && w > 0) {
|
|
278
|
+
pipeline = pipeline.resize(w, null, {
|
|
279
|
+
fit: "inside",
|
|
280
|
+
withoutEnlargement: false
|
|
281
|
+
});
|
|
282
|
+
} else if (processMode === "auto" && w > 0) {
|
|
283
|
+
pipeline = pipeline.resize(w, null, {
|
|
284
|
+
fit: "inside",
|
|
285
|
+
withoutEnlargement: true
|
|
286
|
+
});
|
|
287
|
+
} else if (w > 0 || h > 0) {
|
|
288
|
+
pipeline = pipeline.resize(w || null, h || null, {
|
|
289
|
+
fit: "inside",
|
|
290
|
+
withoutEnlargement: true
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
const reqFmt = String(opts.requestedFormat || "").trim().toLowerCase();
|
|
294
|
+
const preferWebp = reqFmt === "webp" || !reqFmt && (opts.defaultFormat || "webp") === "webp";
|
|
295
|
+
let contentType = sourceMime || "image/webp";
|
|
296
|
+
let ext = ".webp";
|
|
297
|
+
if (reqFmt === "avif") {
|
|
298
|
+
pipeline = pipeline.avif({ quality: q });
|
|
299
|
+
contentType = "image/avif";
|
|
300
|
+
ext = ".avif";
|
|
301
|
+
} else if (reqFmt === "png") {
|
|
302
|
+
pipeline = pipeline.png({ quality: q });
|
|
303
|
+
contentType = "image/png";
|
|
304
|
+
ext = ".png";
|
|
305
|
+
} else if (reqFmt === "jpg" || reqFmt === "jpeg") {
|
|
306
|
+
pipeline = pipeline.jpeg({ quality: q, mozjpeg: true });
|
|
307
|
+
contentType = "image/jpeg";
|
|
308
|
+
ext = ".jpg";
|
|
309
|
+
} else if (preferWebp || sourceMime === "image/webp") {
|
|
310
|
+
pipeline = pipeline.webp({ quality: q, alphaQuality: 100, effort: 4 });
|
|
311
|
+
contentType = "image/webp";
|
|
312
|
+
ext = ".webp";
|
|
313
|
+
} else if (sourceMime === "image/avif") {
|
|
314
|
+
pipeline = pipeline.avif({ quality: q });
|
|
315
|
+
contentType = "image/avif";
|
|
316
|
+
ext = ".avif";
|
|
317
|
+
} else if (sourceMime === "image/png") {
|
|
318
|
+
pipeline = pipeline.png({ quality: q });
|
|
319
|
+
contentType = "image/png";
|
|
320
|
+
ext = ".png";
|
|
321
|
+
} else {
|
|
322
|
+
pipeline = pipeline.jpeg({ quality: q, mozjpeg: true });
|
|
323
|
+
contentType = "image/jpeg";
|
|
324
|
+
ext = ".jpg";
|
|
325
|
+
}
|
|
326
|
+
const outputBuffer = await pipeline.toBuffer();
|
|
327
|
+
const outMeta = await sharp(outputBuffer).metadata();
|
|
328
|
+
return {
|
|
329
|
+
buffer: outputBuffer,
|
|
330
|
+
contentType,
|
|
331
|
+
ext,
|
|
332
|
+
width: outMeta.width || w || void 0,
|
|
333
|
+
height: outMeta.height || h || void 0
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
async function ensureMediaVariant(strapi, existingFile, spec) {
|
|
337
|
+
const formatKey = computeCiFormatKey(
|
|
338
|
+
spec.processMode,
|
|
339
|
+
spec.w,
|
|
340
|
+
spec.h,
|
|
341
|
+
spec.rotate || 0
|
|
342
|
+
);
|
|
343
|
+
if (!existingFile?.id || !existingFile?.url) {
|
|
344
|
+
return { formatKey, formatEntry: null, updatedFile: existingFile };
|
|
345
|
+
}
|
|
346
|
+
if (!isOptimizableRasterImage(existingFile.mime, existingFile.ext || existingFile.url)) {
|
|
347
|
+
return { formatKey, formatEntry: null, updatedFile: existingFile };
|
|
348
|
+
}
|
|
349
|
+
const already = existingFile.formats?.[formatKey];
|
|
350
|
+
if (already?.url) {
|
|
351
|
+
return { formatKey, formatEntry: already, updatedFile: existingFile };
|
|
352
|
+
}
|
|
353
|
+
const lockKey = `${existingFile.id}:${formatKey}`;
|
|
354
|
+
const activePromise = inFlightVariants.get(lockKey);
|
|
355
|
+
if (activePromise) {
|
|
356
|
+
return activePromise;
|
|
357
|
+
}
|
|
358
|
+
const task = (async () => {
|
|
359
|
+
const cfg = getVariantConfig(strapi);
|
|
360
|
+
const freshCheck = await strapi.db.query("plugin::upload.file").findOne({
|
|
361
|
+
where: { id: existingFile.id }
|
|
362
|
+
});
|
|
363
|
+
const baseRecord = freshCheck || existingFile;
|
|
364
|
+
if (baseRecord.formats?.[formatKey]?.url) {
|
|
365
|
+
return {
|
|
366
|
+
formatKey,
|
|
367
|
+
formatEntry: baseRecord.formats[formatKey],
|
|
368
|
+
updatedFile: baseRecord
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
const { buffer: sourceBuffer, mime: sourceMime } = await loadSourceBuffer(
|
|
372
|
+
strapi,
|
|
373
|
+
baseRecord.url
|
|
374
|
+
);
|
|
375
|
+
const rendered = await renderSharpVariantBuffer(
|
|
376
|
+
sourceBuffer,
|
|
377
|
+
baseRecord.mime || sourceMime,
|
|
378
|
+
{
|
|
379
|
+
processMode: spec.processMode,
|
|
380
|
+
w: spec.w,
|
|
381
|
+
h: spec.h,
|
|
382
|
+
q: spec.q || cfg.defaultQuality,
|
|
383
|
+
rotate: spec.rotate || 0,
|
|
384
|
+
requestedFormat: spec.requestedFormat,
|
|
385
|
+
defaultFormat: cfg.defaultFormat
|
|
386
|
+
}
|
|
387
|
+
);
|
|
388
|
+
const fallbackShortHash = crypto.createHash("sha1").update(String(baseRecord.url)).digest("hex").slice(0, 10);
|
|
389
|
+
const cleanBaseName = path.basename(
|
|
390
|
+
baseRecord.name || "image",
|
|
391
|
+
path.extname(baseRecord.name || "")
|
|
392
|
+
);
|
|
393
|
+
const variantHash = `${formatKey}_${baseRecord.hash || fallbackShortHash}`;
|
|
394
|
+
const variantName = `${formatKey}_${cleanBaseName}${rendered.ext}`;
|
|
395
|
+
const tmpVariantPath = path.join(
|
|
396
|
+
os.tmpdir(),
|
|
397
|
+
`${variantHash}_${Date.now()}_${Math.random().toString(36).slice(2, 6)}${rendered.ext}`
|
|
398
|
+
);
|
|
399
|
+
await fs.promises.writeFile(tmpVariantPath, rendered.buffer);
|
|
400
|
+
try {
|
|
401
|
+
const variantFile = {
|
|
402
|
+
name: variantName,
|
|
403
|
+
hash: variantHash,
|
|
404
|
+
ext: rendered.ext,
|
|
405
|
+
mime: rendered.contentType,
|
|
406
|
+
filepath: tmpVariantPath,
|
|
407
|
+
path: cfg.folder !== null ? cfg.folder : baseRecord.path || null,
|
|
408
|
+
getStream: () => fs.createReadStream(tmpVariantPath),
|
|
409
|
+
width: rendered.width,
|
|
410
|
+
height: rendered.height,
|
|
411
|
+
size: Math.round(rendered.buffer.length / 1e3 * 100) / 100,
|
|
412
|
+
sizeInBytes: rendered.buffer.length
|
|
413
|
+
};
|
|
414
|
+
const providerService = strapi.plugin("upload").service("provider");
|
|
415
|
+
if (!providerService || typeof providerService.upload !== "function") {
|
|
416
|
+
return { formatKey, formatEntry: null, updatedFile: baseRecord };
|
|
417
|
+
}
|
|
418
|
+
await providerService.upload(variantFile);
|
|
419
|
+
const { filepath: _fp, getStream: _gs, ...serializableFormat } = variantFile;
|
|
420
|
+
const latestRecord = await strapi.db.query("plugin::upload.file").findOne({
|
|
421
|
+
where: { id: baseRecord.id }
|
|
422
|
+
}) || baseRecord;
|
|
423
|
+
const nextFormats = {
|
|
424
|
+
...latestRecord.formats || {},
|
|
425
|
+
[formatKey]: serializableFormat
|
|
426
|
+
};
|
|
427
|
+
const updatedFile = await strapi.db.query("plugin::upload.file").update({
|
|
428
|
+
where: { id: baseRecord.id },
|
|
429
|
+
data: { formats: nextFormats }
|
|
430
|
+
});
|
|
431
|
+
existingFile.formats = nextFormats;
|
|
432
|
+
return {
|
|
433
|
+
formatKey,
|
|
434
|
+
formatEntry: serializableFormat,
|
|
435
|
+
updatedFile: updatedFile || { ...latestRecord, formats: nextFormats }
|
|
436
|
+
};
|
|
437
|
+
} finally {
|
|
438
|
+
await fs.promises.rm(tmpVariantPath, { force: true }).catch(() => void 0);
|
|
439
|
+
}
|
|
440
|
+
})();
|
|
441
|
+
inFlightVariants.set(lockKey, task);
|
|
442
|
+
try {
|
|
443
|
+
return await task;
|
|
444
|
+
} finally {
|
|
445
|
+
inFlightVariants.delete(lockKey);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
async function clearGeneratedCiVariantsForFile(strapi, fileRecord) {
|
|
449
|
+
if (!fileRecord?.id || !fileRecord?.formats || typeof fileRecord.formats !== "object") {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const providerService = strapi.plugin("upload")?.service?.("provider");
|
|
453
|
+
const nextFormats = {};
|
|
454
|
+
const removedFormats = [];
|
|
455
|
+
for (const [k, fmt] of Object.entries(fileRecord.formats)) {
|
|
456
|
+
if (k.startsWith("ci_")) {
|
|
457
|
+
removedFormats.push(fmt);
|
|
458
|
+
} else {
|
|
459
|
+
nextFormats[k] = fmt;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (removedFormats.length === 0) return;
|
|
463
|
+
if (providerService && typeof providerService.delete === "function") {
|
|
464
|
+
for (const fmt of removedFormats) {
|
|
465
|
+
try {
|
|
466
|
+
await providerService.delete(fmt);
|
|
467
|
+
} catch {
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
await strapi.db.query("plugin::upload.file").update({
|
|
472
|
+
where: { id: fileRecord.id },
|
|
473
|
+
data: { formats: nextFormats }
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
async function enrichMediaAssetNode(strapi, asset, opts = {}) {
|
|
477
|
+
if (!asset) return asset;
|
|
478
|
+
const isStringInput = typeof asset === "string";
|
|
479
|
+
const rawUrl = isStringInput ? asset : asset.original_url || asset.url || asset.target_url || asset.src || "";
|
|
480
|
+
if (!rawUrl || typeof rawUrl !== "string") return asset;
|
|
481
|
+
const fileRecord = await findUploadFileForAsset(strapi, asset, opts.fileCache);
|
|
482
|
+
if (!fileRecord) {
|
|
483
|
+
return asset;
|
|
484
|
+
}
|
|
485
|
+
const canonicalMasterUrl = fileRecord.url || rawUrl;
|
|
486
|
+
if (!isOptimizableRasterImage(fileRecord.mime, fileRecord.ext || canonicalMasterUrl)) {
|
|
487
|
+
if (isStringInput) return canonicalMasterUrl;
|
|
488
|
+
return {
|
|
489
|
+
...asset,
|
|
490
|
+
id: fileRecord.id,
|
|
491
|
+
hash: fileRecord.hash,
|
|
492
|
+
original_url: canonicalMasterUrl,
|
|
493
|
+
url: canonicalMasterUrl,
|
|
494
|
+
target_url: canonicalMasterUrl
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
const spec = normalizeImageProcessSpec(
|
|
498
|
+
opts.imageSettings,
|
|
499
|
+
opts.defaultAutoMaxW || 1920
|
|
500
|
+
);
|
|
501
|
+
let latestFile = fileRecord;
|
|
502
|
+
let activeVariantUrl;
|
|
503
|
+
if (spec.processMode !== "none") {
|
|
504
|
+
try {
|
|
505
|
+
const primary = await ensureMediaVariant(strapi, latestFile, {
|
|
506
|
+
processMode: spec.processMode,
|
|
507
|
+
w: spec.w,
|
|
508
|
+
h: spec.h,
|
|
509
|
+
q: spec.q,
|
|
510
|
+
rotate: spec.rotate
|
|
511
|
+
});
|
|
512
|
+
latestFile = primary.updatedFile || latestFile;
|
|
513
|
+
if (primary.formatEntry?.url) {
|
|
514
|
+
activeVariantUrl = primary.formatEntry.url;
|
|
515
|
+
}
|
|
516
|
+
} catch (err) {
|
|
517
|
+
strapi.log?.warn?.(
|
|
518
|
+
`[content-input] Image variant generation skipped for "${canonicalMasterUrl}": ${err?.message || err}`
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if (opts.alsoEnsureAutoMaxW && opts.alsoEnsureAutoMaxW > 0 && spec.processMode !== "none" && !(spec.processMode === "auto" && spec.w === opts.alsoEnsureAutoMaxW)) {
|
|
523
|
+
try {
|
|
524
|
+
const secondary = await ensureMediaVariant(strapi, latestFile, {
|
|
525
|
+
processMode: "auto",
|
|
526
|
+
w: opts.alsoEnsureAutoMaxW,
|
|
527
|
+
h: 0,
|
|
528
|
+
q: spec.q
|
|
529
|
+
});
|
|
530
|
+
latestFile = secondary.updatedFile || latestFile;
|
|
531
|
+
} catch {
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (opts.fileCache && latestFile?.id) {
|
|
535
|
+
opts.fileCache.set(`id:${latestFile.id}`, latestFile);
|
|
536
|
+
if (latestFile.hash) opts.fileCache.set(`hash:${latestFile.hash}`, latestFile);
|
|
537
|
+
if (latestFile.url) opts.fileCache.set(`url:${String(latestFile.url).split("?")[0]}`, latestFile);
|
|
538
|
+
}
|
|
539
|
+
const compactFormats = compactAssetFormats(latestFile.formats);
|
|
540
|
+
if (isStringInput) {
|
|
541
|
+
return activeVariantUrl || canonicalMasterUrl;
|
|
542
|
+
}
|
|
543
|
+
const nextAsset = {
|
|
544
|
+
...asset,
|
|
545
|
+
id: latestFile.id,
|
|
546
|
+
hash: latestFile.hash,
|
|
547
|
+
original_url: canonicalMasterUrl,
|
|
548
|
+
url: canonicalMasterUrl,
|
|
549
|
+
target_url: canonicalMasterUrl,
|
|
550
|
+
filename: asset.filename || asset.name || latestFile.name || "image",
|
|
551
|
+
mime_type: asset.mime_type || latestFile.mime || "image/webp",
|
|
552
|
+
width: asset.width || latestFile.width || void 0,
|
|
553
|
+
height: asset.height || latestFile.height || void 0
|
|
554
|
+
};
|
|
555
|
+
if (spec.processMode === "none") {
|
|
556
|
+
delete nextAsset.optimized_url;
|
|
557
|
+
} else if (activeVariantUrl) {
|
|
558
|
+
nextAsset.optimized_url = activeVariantUrl;
|
|
559
|
+
}
|
|
560
|
+
if (compactFormats) {
|
|
561
|
+
nextAsset.formats = compactFormats;
|
|
562
|
+
}
|
|
563
|
+
return nextAsset;
|
|
564
|
+
}
|
|
565
|
+
async function runWithConcurrency(tasks, concurrency = 3) {
|
|
566
|
+
const results = new Array(tasks.length);
|
|
567
|
+
let cursor = 0;
|
|
568
|
+
async function worker() {
|
|
569
|
+
while (cursor < tasks.length) {
|
|
570
|
+
const idx = cursor++;
|
|
571
|
+
results[idx] = await tasks[idx]();
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
const poolSize = Math.min(Math.max(1, concurrency), tasks.length);
|
|
575
|
+
await Promise.all(Array.from({ length: poolSize }, () => worker()));
|
|
576
|
+
return results;
|
|
577
|
+
}
|
|
578
|
+
async function optimizeHtmlImgSources(strapi, html, fileCache) {
|
|
579
|
+
if (!html || typeof html !== "string" || !html.includes("<img")) return html;
|
|
580
|
+
const imgRegex = /(<img\b[^>]*?\bsrc=(["']))([^"']+)(\2[^>]*>)/gi;
|
|
581
|
+
const matches = Array.from(html.matchAll(imgRegex));
|
|
582
|
+
if (matches.length === 0) return html;
|
|
583
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
584
|
+
const uniqueSrcs = Array.from(new Set(matches.map((m) => m[3]).filter(Boolean)));
|
|
585
|
+
await runWithConcurrency(
|
|
586
|
+
uniqueSrcs.map((srcUrl) => async () => {
|
|
587
|
+
if (!isOptimizableRasterImage(void 0, srcUrl)) return;
|
|
588
|
+
const fileRecord = await findUploadFileForAsset(strapi, srcUrl, fileCache);
|
|
589
|
+
if (!fileRecord) return;
|
|
590
|
+
if (!isOptimizableRasterImage(fileRecord.mime, fileRecord.ext || fileRecord.url)) return;
|
|
591
|
+
try {
|
|
592
|
+
const res = await ensureMediaVariant(strapi, fileRecord, {
|
|
593
|
+
processMode: "auto",
|
|
594
|
+
w: 1600,
|
|
595
|
+
h: 0
|
|
596
|
+
});
|
|
597
|
+
if (res.formatEntry?.url) {
|
|
598
|
+
replacements.set(srcUrl, res.formatEntry.url);
|
|
599
|
+
}
|
|
600
|
+
} catch {
|
|
601
|
+
}
|
|
602
|
+
}),
|
|
603
|
+
3
|
|
604
|
+
);
|
|
605
|
+
if (replacements.size === 0) return html;
|
|
606
|
+
return html.replace(imgRegex, (full, prefix, _quote, srcVal, suffix) => {
|
|
607
|
+
const nextUrl = replacements.get(srcVal);
|
|
608
|
+
return nextUrl ? `${prefix}${nextUrl}${suffix}` : full;
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
async function syncContentInputTreeMedia(strapi, rawValue) {
|
|
612
|
+
if (!rawValue) return rawValue;
|
|
613
|
+
const wasString = typeof rawValue === "string";
|
|
614
|
+
let parsed = rawValue;
|
|
615
|
+
if (wasString) {
|
|
616
|
+
const trimmed = rawValue.trim();
|
|
617
|
+
if (!trimmed) return rawValue;
|
|
618
|
+
try {
|
|
619
|
+
parsed = JSON.parse(trimmed);
|
|
620
|
+
} catch {
|
|
621
|
+
return rawValue;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
if (!Array.isArray(parsed)) {
|
|
625
|
+
return rawValue;
|
|
626
|
+
}
|
|
627
|
+
const rows = JSON.parse(JSON.stringify(parsed));
|
|
628
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
629
|
+
const jobs = [];
|
|
630
|
+
const scheduleAsset = (holder, key, opts) => {
|
|
631
|
+
const current = holder?.[key];
|
|
632
|
+
if (!current) return;
|
|
633
|
+
jobs.push(async () => {
|
|
634
|
+
holder[key] = await enrichMediaAssetNode(strapi, current, {
|
|
635
|
+
...opts,
|
|
636
|
+
fileCache
|
|
637
|
+
});
|
|
638
|
+
});
|
|
639
|
+
};
|
|
640
|
+
const scheduleHtml = (holder, key) => {
|
|
641
|
+
const val = holder?.[key];
|
|
642
|
+
if (typeof val !== "string" || !val.includes("<img")) return;
|
|
643
|
+
jobs.push(async () => {
|
|
644
|
+
holder[key] = await optimizeHtmlImgSources(strapi, val, fileCache);
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
const walkRows = (rowList) => {
|
|
648
|
+
if (!Array.isArray(rowList)) return;
|
|
649
|
+
for (const row of rowList) {
|
|
650
|
+
if (!row || typeof row !== "object") continue;
|
|
651
|
+
if (row.bgImage) {
|
|
652
|
+
scheduleAsset(row, "bgImage", {
|
|
653
|
+
imageSettings: row.bgOptions?.imageSettings,
|
|
654
|
+
defaultAutoMaxW: 1920
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
const blocks = Array.isArray(row.blocks) ? row.blocks : [];
|
|
658
|
+
for (const block of blocks) {
|
|
659
|
+
if (!block || typeof block !== "object") continue;
|
|
660
|
+
if (block.bgImage) {
|
|
661
|
+
scheduleAsset(block, "bgImage", {
|
|
662
|
+
imageSettings: block.bgOptions?.imageSettings,
|
|
663
|
+
defaultAutoMaxW: 1920
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
const widgets = Array.isArray(block.widgets) ? block.widgets : [];
|
|
667
|
+
for (const widget of widgets) {
|
|
668
|
+
if (!widget || typeof widget !== "object") continue;
|
|
669
|
+
const wId = widget.id;
|
|
670
|
+
const wOpts = widget.options || {};
|
|
671
|
+
const wData = widget.data;
|
|
672
|
+
if (wId === "gallery") {
|
|
673
|
+
const list = Array.isArray(wData) ? wData : Array.isArray(wData?.images) ? wData.images : null;
|
|
674
|
+
if (list) {
|
|
675
|
+
const popupEnabled = wOpts.popup !== false;
|
|
676
|
+
for (let i = 0; i < list.length; i++) {
|
|
677
|
+
scheduleAsset(list, i, {
|
|
678
|
+
imageSettings: wOpts.imageSettings,
|
|
679
|
+
defaultAutoMaxW: 1600,
|
|
680
|
+
alsoEnsureAutoMaxW: popupEnabled ? 1920 : 0
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
} else if (wId === "singleImage" && wData && typeof wData === "object") {
|
|
685
|
+
if (wData.image) {
|
|
686
|
+
scheduleAsset(wData, "image", {
|
|
687
|
+
imageSettings: wOpts.imageSettings || wData.imageSettings,
|
|
688
|
+
defaultAutoMaxW: 1920
|
|
689
|
+
});
|
|
690
|
+
} else if (wData.url || wData.target_url) {
|
|
691
|
+
scheduleAsset(widget, "data", {
|
|
692
|
+
imageSettings: wOpts.imageSettings,
|
|
693
|
+
defaultAutoMaxW: 1920
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
} else if (wId === "banner" && wData && typeof wData === "object") {
|
|
697
|
+
if (wData.image) {
|
|
698
|
+
scheduleAsset(wData, "image", {
|
|
699
|
+
imageSettings: wOpts.imageSettings || wData.imageSettings,
|
|
700
|
+
defaultAutoMaxW: 1920
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
} else if (wId === "youtubeVideo") {
|
|
704
|
+
if (wOpts.thumbnailImage) {
|
|
705
|
+
scheduleAsset(wOpts, "thumbnailImage", {
|
|
706
|
+
imageSettings: wOpts.imageSettings,
|
|
707
|
+
defaultAutoMaxW: 1280
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
if (Array.isArray(wData)) {
|
|
711
|
+
for (const vid of wData) {
|
|
712
|
+
if (vid && typeof vid === "object" && vid.customThumbnail) {
|
|
713
|
+
scheduleAsset(vid, "customThumbnail", {
|
|
714
|
+
imageSettings: wOpts.imageSettings,
|
|
715
|
+
defaultAutoMaxW: 1280
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
} else if (wData && typeof wData === "object" && wData.customThumbnail) {
|
|
720
|
+
scheduleAsset(wData, "customThumbnail", {
|
|
721
|
+
imageSettings: wOpts.imageSettings,
|
|
722
|
+
defaultAutoMaxW: 1280
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
} else if (wId === "heroSlider" && wData && typeof wData === "object") {
|
|
726
|
+
const globalHeroImgSettings = wData.settings?.imageSettings || wOpts.imageSettings;
|
|
727
|
+
const slides = Array.isArray(wData.slides) ? wData.slides : [];
|
|
728
|
+
for (const slide of slides) {
|
|
729
|
+
if (!slide || typeof slide !== "object") continue;
|
|
730
|
+
if (slide.bgImage) {
|
|
731
|
+
scheduleAsset(slide, "bgImage", {
|
|
732
|
+
imageSettings: slide.imageSettings || globalHeroImgSettings,
|
|
733
|
+
defaultAutoMaxW: 1920
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
if (slide.mobileBgImage) {
|
|
737
|
+
scheduleAsset(slide, "mobileBgImage", {
|
|
738
|
+
imageSettings: slide.mobileImageSettings,
|
|
739
|
+
defaultAutoMaxW: 1080
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
const layers = Array.isArray(slide.layers) ? slide.layers : [];
|
|
743
|
+
for (const layer of layers) {
|
|
744
|
+
if (layer && typeof layer === "object" && layer.image) {
|
|
745
|
+
scheduleAsset(layer, "image", {
|
|
746
|
+
imageSettings: layer.imageSettings,
|
|
747
|
+
defaultAutoMaxW: 1200
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
} else if (wId === "customCard" && wData && typeof wData === "object") {
|
|
753
|
+
const cardImgSettings = wData.design?.imageSettings || wOpts.imageSettings;
|
|
754
|
+
const cards = Array.isArray(wData.cards) ? wData.cards : [];
|
|
755
|
+
for (const card of cards) {
|
|
756
|
+
if (!card || typeof card !== "object") continue;
|
|
757
|
+
if (card.image) {
|
|
758
|
+
scheduleAsset(card, "image", {
|
|
759
|
+
imageSettings: cardImgSettings,
|
|
760
|
+
defaultAutoMaxW: 960
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
if (card.authorAvatar) {
|
|
764
|
+
scheduleAsset(card, "authorAvatar", {
|
|
765
|
+
imageSettings: { process: "fit", cWidth: 240, cHeight: 240 },
|
|
766
|
+
defaultAutoMaxW: 240
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
} else if (wId === "entityCard" && wData && typeof wData === "object") {
|
|
771
|
+
const ecImgSettings = wOpts.imageSettings || wOpts.cardProps?.imageSettings;
|
|
772
|
+
if (wData.overrides?.image) {
|
|
773
|
+
scheduleAsset(wData.overrides, "image", {
|
|
774
|
+
imageSettings: ecImgSettings,
|
|
775
|
+
defaultAutoMaxW: 960
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
if (wData.entity?.image) {
|
|
779
|
+
scheduleAsset(wData.entity, "image", {
|
|
780
|
+
imageSettings: ecImgSettings,
|
|
781
|
+
defaultAutoMaxW: 960
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
if (Array.isArray(wData.items)) {
|
|
785
|
+
for (const item of wData.items) {
|
|
786
|
+
if (!item || typeof item !== "object") continue;
|
|
787
|
+
if (item.overrides?.image) {
|
|
788
|
+
scheduleAsset(item.overrides, "image", {
|
|
789
|
+
imageSettings: ecImgSettings,
|
|
790
|
+
defaultAutoMaxW: 960
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
if (item.entity?.image) {
|
|
794
|
+
scheduleAsset(item.entity, "image", {
|
|
795
|
+
imageSettings: ecImgSettings,
|
|
796
|
+
defaultAutoMaxW: 960
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
} else if (wId === "HtmlEditor") {
|
|
802
|
+
if (typeof wData === "string") {
|
|
803
|
+
scheduleHtml(widget, "data");
|
|
804
|
+
} else if (wData && typeof wData === "object" && typeof wData.content === "string") {
|
|
805
|
+
scheduleHtml(wData, "content");
|
|
806
|
+
}
|
|
807
|
+
} else if (wId === "tab" || wId === "accordion") {
|
|
808
|
+
const nodes = Array.isArray(wData) ? wData : Array.isArray(wData?.nodes) ? wData.nodes : Array.isArray(wData?.tabs) ? wData.tabs : [];
|
|
809
|
+
for (const node of nodes) {
|
|
810
|
+
if (!node || typeof node !== "object") continue;
|
|
811
|
+
if (Array.isArray(node.rows)) walkRows(node.rows);
|
|
812
|
+
if (Array.isArray(node.content)) walkRows(node.content);
|
|
813
|
+
if (Array.isArray(node.content?.data)) walkRows(node.content.data);
|
|
814
|
+
if (typeof node.html === "string") scheduleHtml(node, "html");
|
|
815
|
+
if (typeof node.content === "string") scheduleHtml(node, "content");
|
|
816
|
+
if (typeof node.content?.html === "string") scheduleHtml(node.content, "html");
|
|
817
|
+
}
|
|
818
|
+
} else if (wId === "survey" && wData && typeof wData === "object") {
|
|
819
|
+
const qLists = [wData.questions, wData.survey?.questions].filter(Array.isArray);
|
|
820
|
+
for (const qList of qLists) {
|
|
821
|
+
for (const q of qList) {
|
|
822
|
+
if (!q || typeof q !== "object" || !Array.isArray(q.options)) continue;
|
|
823
|
+
for (const opt of q.options) {
|
|
824
|
+
if (opt && typeof opt === "object" && opt.image) {
|
|
825
|
+
scheduleAsset(opt, "image", {
|
|
826
|
+
defaultAutoMaxW: 800
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
} else if (wId === "dataTable" && wData && typeof wData === "object") {
|
|
833
|
+
const cols = Array.isArray(wData.columns) ? wData.columns : [];
|
|
834
|
+
const imageColKeys = cols.filter((c) => c && c.type === "image" && c.key).map((c) => String(c.key));
|
|
835
|
+
const dtRows = Array.isArray(wData.rows) ? wData.rows : [];
|
|
836
|
+
if (imageColKeys.length > 0 && dtRows.length > 0) {
|
|
837
|
+
for (const dtRow of dtRows) {
|
|
838
|
+
if (!dtRow || typeof dtRow !== "object") continue;
|
|
839
|
+
for (const key of imageColKeys) {
|
|
840
|
+
if (dtRow[key]) {
|
|
841
|
+
scheduleAsset(dtRow, key, {
|
|
842
|
+
defaultAutoMaxW: 800
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
walkRows(rows);
|
|
854
|
+
if (jobs.length > 0) {
|
|
855
|
+
await runWithConcurrency(jobs, 3);
|
|
856
|
+
}
|
|
857
|
+
return wasString ? JSON.stringify(rows) : rows;
|
|
858
|
+
}
|
|
859
|
+
async function syncSurveyQuestionsMedia(strapi, questions) {
|
|
860
|
+
if (!Array.isArray(questions) || questions.length === 0) return questions;
|
|
861
|
+
const cloned = JSON.parse(JSON.stringify(questions));
|
|
862
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
863
|
+
const jobs = [];
|
|
864
|
+
for (const q of cloned) {
|
|
865
|
+
if (!q || typeof q !== "object" || !Array.isArray(q.options)) continue;
|
|
866
|
+
for (const opt of q.options) {
|
|
867
|
+
if (opt && typeof opt === "object" && opt.image) {
|
|
868
|
+
jobs.push(async () => {
|
|
869
|
+
opt.image = await enrichMediaAssetNode(strapi, opt.image, {
|
|
870
|
+
defaultAutoMaxW: 800,
|
|
871
|
+
fileCache
|
|
872
|
+
});
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
if (jobs.length > 0) {
|
|
878
|
+
await runWithConcurrency(jobs, 3);
|
|
879
|
+
}
|
|
880
|
+
return cloned;
|
|
881
|
+
}
|
|
882
|
+
function collectContentInputModelFields(strapi) {
|
|
883
|
+
const map = /* @__PURE__ */ new Map();
|
|
884
|
+
const inspectSchemas = (schemas) => {
|
|
885
|
+
if (!schemas || typeof schemas !== "object") return;
|
|
886
|
+
for (const [uid, schema] of Object.entries(schemas)) {
|
|
887
|
+
const attrs = schema?.attributes;
|
|
888
|
+
if (!attrs || typeof attrs !== "object") continue;
|
|
889
|
+
const matchingFields = [];
|
|
890
|
+
for (const [fieldName, attrDef] of Object.entries(attrs)) {
|
|
891
|
+
if (attrDef?.customField === "plugin::content-input.content-input") {
|
|
892
|
+
matchingFields.push(fieldName);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
if (matchingFields.length > 0) {
|
|
896
|
+
map.set(uid, matchingFields);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
inspectSchemas(strapi.contentTypes);
|
|
901
|
+
inspectSchemas(strapi.components);
|
|
902
|
+
return map;
|
|
903
|
+
}
|
|
17
904
|
const bootstrap = async ({ strapi }) => {
|
|
18
905
|
try {
|
|
906
|
+
await strapi.plugin("content-input").service("ci-color").ensureSeeded();
|
|
19
907
|
await strapi.plugin("content-input").service("ci-form").ensureSeeded();
|
|
20
908
|
await strapi.plugin("content-input").service("ci-survey").ensureSeeded(false);
|
|
21
909
|
} catch (err) {
|
|
22
910
|
strapi.log.warn(`[content-input] Bootstrap seed skipped: ${err?.message || err}`);
|
|
23
911
|
}
|
|
912
|
+
try {
|
|
913
|
+
const modelFieldMap = collectContentInputModelFields(strapi);
|
|
914
|
+
const surveyUid = "plugin::content-input.ci-survey";
|
|
915
|
+
const subscribedModels = Array.from(/* @__PURE__ */ new Set([...modelFieldMap.keys(), surveyUid]));
|
|
916
|
+
if (subscribedModels.length > 0 && strapi.db?.lifecycles?.subscribe) {
|
|
917
|
+
const processEventData = async (event) => {
|
|
918
|
+
const uid = event?.model?.uid;
|
|
919
|
+
const data = event?.params?.data;
|
|
920
|
+
if (!uid || !data || typeof data !== "object") return;
|
|
921
|
+
if (uid === surveyUid) {
|
|
922
|
+
if (Array.isArray(data.questions) && data.questions.length > 0) {
|
|
923
|
+
try {
|
|
924
|
+
data.questions = await syncSurveyQuestionsMedia(strapi, data.questions);
|
|
925
|
+
} catch (err) {
|
|
926
|
+
strapi.log.warn(
|
|
927
|
+
`[content-input] Survey media optimization warning: ${err?.message || err}`
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
const fields = modelFieldMap.get(uid);
|
|
934
|
+
if (!fields || fields.length === 0) return;
|
|
935
|
+
for (const fieldName of fields) {
|
|
936
|
+
if (data[fieldName] !== void 0 && data[fieldName] !== null) {
|
|
937
|
+
try {
|
|
938
|
+
data[fieldName] = await syncContentInputTreeMedia(strapi, data[fieldName]);
|
|
939
|
+
} catch (err) {
|
|
940
|
+
strapi.log.warn(
|
|
941
|
+
`[content-input] Media sync warning on ${uid}.${fieldName}: ${err?.message || err}`
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
strapi.db.lifecycles.subscribe({
|
|
948
|
+
models: subscribedModels,
|
|
949
|
+
async beforeCreate(event) {
|
|
950
|
+
await processEventData(event);
|
|
951
|
+
},
|
|
952
|
+
async beforeUpdate(event) {
|
|
953
|
+
await processEventData(event);
|
|
954
|
+
}
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
} catch (err) {
|
|
958
|
+
strapi.log.warn(
|
|
959
|
+
`[content-input] Lifecycle registration skipped: ${err?.message || err}`
|
|
960
|
+
);
|
|
961
|
+
}
|
|
24
962
|
};
|
|
25
963
|
const destroy = ({ strapi }) => {
|
|
26
964
|
};
|
|
27
965
|
const config = {
|
|
28
966
|
default: {
|
|
29
|
-
previewUrl: "/ci-preview"
|
|
967
|
+
previewUrl: "/ci-preview",
|
|
968
|
+
imageVariantFolder: process.env.CI_IMAGE_VARIANT_FOLDER || "ci-optimized",
|
|
969
|
+
imageVariantFormat: process.env.CI_IMAGE_VARIANT_FORMAT || "webp",
|
|
970
|
+
imageVariantQuality: 85,
|
|
971
|
+
redirectProxyToCdn: true
|
|
30
972
|
},
|
|
31
973
|
validator() {
|
|
32
974
|
}
|
|
33
975
|
};
|
|
976
|
+
const kind$6 = "collectionType";
|
|
977
|
+
const collectionName$6 = "ci_templates";
|
|
978
|
+
const info$6 = { "singularName": "ci-template", "pluralName": "ci-templates", "displayName": "ContentInput Template", "description": "Saved visual editor row/section templates" };
|
|
979
|
+
const options$6 = { "draftAndPublish": false };
|
|
980
|
+
const pluginOptions$6 = { "content-manager": { "visible": false }, "content-type-builder": { "visible": false } };
|
|
981
|
+
const attributes$6 = { "name": { "type": "string", "required": true }, "category": { "type": "string", "default": "custom" }, "structure": { "type": "json", "required": true }, "thumbnail": { "type": "string", "default": "" } };
|
|
982
|
+
const templateSchema = {
|
|
983
|
+
kind: kind$6,
|
|
984
|
+
collectionName: collectionName$6,
|
|
985
|
+
info: info$6,
|
|
986
|
+
options: options$6,
|
|
987
|
+
pluginOptions: pluginOptions$6,
|
|
988
|
+
attributes: attributes$6
|
|
989
|
+
};
|
|
34
990
|
const kind$5 = "collectionType";
|
|
35
|
-
const collectionName$5 = "
|
|
36
|
-
const info$5 = { "singularName": "ci-
|
|
991
|
+
const collectionName$5 = "ci_menus";
|
|
992
|
+
const info$5 = { "singularName": "ci-menu", "pluralName": "ci-menus", "displayName": "ContentInput Menu", "description": "Reusable nested menus (horizontal & vertical) for ContentInput" };
|
|
37
993
|
const options$5 = { "draftAndPublish": false };
|
|
38
994
|
const pluginOptions$5 = { "content-manager": { "visible": false }, "content-type-builder": { "visible": false } };
|
|
39
|
-
const attributes$5 = { "name": { "type": "string", "required": true }, "
|
|
40
|
-
const
|
|
995
|
+
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" } };
|
|
996
|
+
const menuSchema = {
|
|
41
997
|
kind: kind$5,
|
|
42
998
|
collectionName: collectionName$5,
|
|
43
999
|
info: info$5,
|
|
@@ -46,12 +1002,12 @@ const templateSchema = {
|
|
|
46
1002
|
attributes: attributes$5
|
|
47
1003
|
};
|
|
48
1004
|
const kind$4 = "collectionType";
|
|
49
|
-
const collectionName$4 = "
|
|
50
|
-
const info$4 = { "singularName": "ci-
|
|
1005
|
+
const collectionName$4 = "ci_forms";
|
|
1006
|
+
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" };
|
|
51
1007
|
const options$4 = { "draftAndPublish": false };
|
|
52
|
-
const pluginOptions$4 = { "content-manager": { "visible":
|
|
53
|
-
const attributes$4 = { "
|
|
54
|
-
const
|
|
1008
|
+
const pluginOptions$4 = { "content-manager": { "visible": true }, "content-type-builder": { "visible": false } };
|
|
1009
|
+
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 } };
|
|
1010
|
+
const formSchema = {
|
|
55
1011
|
kind: kind$4,
|
|
56
1012
|
collectionName: collectionName$4,
|
|
57
1013
|
info: info$4,
|
|
@@ -60,12 +1016,12 @@ const menuSchema = {
|
|
|
60
1016
|
attributes: attributes$4
|
|
61
1017
|
};
|
|
62
1018
|
const kind$3 = "collectionType";
|
|
63
|
-
const collectionName$3 = "
|
|
64
|
-
const info$3 = { "singularName": "ci-form", "pluralName": "ci-
|
|
1019
|
+
const collectionName$3 = "ci_form_submissions";
|
|
1020
|
+
const info$3 = { "singularName": "ci-form-submission", "pluralName": "ci-form-submissions", "displayName": "ContentInput Form Submission", "description": "Submitted entries from ContentInput dynamic forms" };
|
|
65
1021
|
const options$3 = { "draftAndPublish": false };
|
|
66
1022
|
const pluginOptions$3 = { "content-manager": { "visible": true }, "content-type-builder": { "visible": false } };
|
|
67
|
-
const attributes$3 = { "
|
|
68
|
-
const
|
|
1023
|
+
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" } };
|
|
1024
|
+
const formSubmissionSchema = {
|
|
69
1025
|
kind: kind$3,
|
|
70
1026
|
collectionName: collectionName$3,
|
|
71
1027
|
info: info$3,
|
|
@@ -74,12 +1030,12 @@ const formSchema = {
|
|
|
74
1030
|
attributes: attributes$3
|
|
75
1031
|
};
|
|
76
1032
|
const kind$2 = "collectionType";
|
|
77
|
-
const collectionName$2 = "
|
|
78
|
-
const info$2 = { "singularName": "ci-
|
|
1033
|
+
const collectionName$2 = "ci_surveys";
|
|
1034
|
+
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" };
|
|
79
1035
|
const options$2 = { "draftAndPublish": false };
|
|
80
1036
|
const pluginOptions$2 = { "content-manager": { "visible": true }, "content-type-builder": { "visible": false } };
|
|
81
|
-
const attributes$2 = { "
|
|
82
|
-
const
|
|
1037
|
+
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 } };
|
|
1038
|
+
const surveySchema = {
|
|
83
1039
|
kind: kind$2,
|
|
84
1040
|
collectionName: collectionName$2,
|
|
85
1041
|
info: info$2,
|
|
@@ -88,12 +1044,12 @@ const formSubmissionSchema = {
|
|
|
88
1044
|
attributes: attributes$2
|
|
89
1045
|
};
|
|
90
1046
|
const kind$1 = "collectionType";
|
|
91
|
-
const collectionName$1 = "
|
|
92
|
-
const info$1 = { "singularName": "ci-survey", "pluralName": "ci-
|
|
1047
|
+
const collectionName$1 = "ci_survey_responses";
|
|
1048
|
+
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" };
|
|
93
1049
|
const options$1 = { "draftAndPublish": false };
|
|
94
1050
|
const pluginOptions$1 = { "content-manager": { "visible": true }, "content-type-builder": { "visible": false } };
|
|
95
|
-
const attributes$1 = { "
|
|
96
|
-
const
|
|
1051
|
+
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" } };
|
|
1052
|
+
const surveyResponseSchema = {
|
|
97
1053
|
kind: kind$1,
|
|
98
1054
|
collectionName: collectionName$1,
|
|
99
1055
|
info: info$1,
|
|
@@ -102,12 +1058,12 @@ const surveySchema = {
|
|
|
102
1058
|
attributes: attributes$1
|
|
103
1059
|
};
|
|
104
1060
|
const kind = "collectionType";
|
|
105
|
-
const collectionName = "
|
|
106
|
-
const info = { "singularName": "ci-
|
|
1061
|
+
const collectionName = "ci_color_palettes";
|
|
1062
|
+
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)" };
|
|
107
1063
|
const options = { "draftAndPublish": false };
|
|
108
|
-
const pluginOptions = { "content-manager": { "visible":
|
|
109
|
-
const attributes = { "
|
|
110
|
-
const
|
|
1064
|
+
const pluginOptions = { "content-manager": { "visible": false }, "content-type-builder": { "visible": false } };
|
|
1065
|
+
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": [] } };
|
|
1066
|
+
const colorPaletteSchema = {
|
|
111
1067
|
kind,
|
|
112
1068
|
collectionName,
|
|
113
1069
|
info,
|
|
@@ -133,6 +1089,9 @@ const contentTypes = {
|
|
|
133
1089
|
},
|
|
134
1090
|
"ci-survey-response": {
|
|
135
1091
|
schema: surveyResponseSchema
|
|
1092
|
+
},
|
|
1093
|
+
"ci-color-palette": {
|
|
1094
|
+
schema: colorPaletteSchema
|
|
136
1095
|
}
|
|
137
1096
|
};
|
|
138
1097
|
const ciTemplateController = ({ strapi }) => ({
|
|
@@ -146,7 +1105,11 @@ const ciTemplateController = ({ strapi }) => ({
|
|
|
146
1105
|
},
|
|
147
1106
|
async save(ctx) {
|
|
148
1107
|
try {
|
|
149
|
-
const
|
|
1108
|
+
const body = ctx.request.body || {};
|
|
1109
|
+
const name = body.name;
|
|
1110
|
+
const structure = body.structure ?? body.rows;
|
|
1111
|
+
const category = body.category;
|
|
1112
|
+
const thumbnail = body.thumbnail;
|
|
150
1113
|
if (!name || !structure) {
|
|
151
1114
|
return ctx.badRequest("Name and structure are required");
|
|
152
1115
|
}
|
|
@@ -256,10 +1219,6 @@ const ciMenuController = ({ strapi }) => ({
|
|
|
256
1219
|
}
|
|
257
1220
|
}
|
|
258
1221
|
});
|
|
259
|
-
function getSharp() {
|
|
260
|
-
const req = typeof require !== "undefined" ? require : createRequire(path.join(process.cwd(), "package.json"));
|
|
261
|
-
return req("sharp");
|
|
262
|
-
}
|
|
263
1222
|
function getCacheDir(strapi) {
|
|
264
1223
|
const rootDir = strapi?.dirs?.app?.root || process.cwd();
|
|
265
1224
|
const dir = path.join(rootDir, ".cache", "content-input-images");
|
|
@@ -268,47 +1227,12 @@ function getCacheDir(strapi) {
|
|
|
268
1227
|
}
|
|
269
1228
|
return dir;
|
|
270
1229
|
}
|
|
271
|
-
async function loadSourceBuffer(strapi, src) {
|
|
272
|
-
const publicDir = strapi?.dirs?.static?.public || path.join(process.cwd(), "public");
|
|
273
|
-
if (src.startsWith("/")) {
|
|
274
|
-
const cleanRel = decodeURIComponent(src.split("?")[0]).replace(/^\/+/, "");
|
|
275
|
-
const fullPath = path.resolve(publicDir, cleanRel);
|
|
276
|
-
const resolvedPublic = path.resolve(publicDir);
|
|
277
|
-
if (!fullPath.startsWith(resolvedPublic)) {
|
|
278
|
-
throw new Error("Invalid local file path");
|
|
279
|
-
}
|
|
280
|
-
if (!fs.existsSync(fullPath)) {
|
|
281
|
-
throw new Error(`File not found: ${src}`);
|
|
282
|
-
}
|
|
283
|
-
const buffer = await fs.promises.readFile(fullPath);
|
|
284
|
-
const ext = path.extname(fullPath).toLowerCase();
|
|
285
|
-
const mime = ext === ".png" ? "image/png" : ext === ".webp" ? "image/webp" : ext === ".avif" ? "image/avif" : ext === ".gif" ? "image/gif" : "image/jpeg";
|
|
286
|
-
return { buffer, mime };
|
|
287
|
-
}
|
|
288
|
-
if (/^https?:\/\//i.test(src)) {
|
|
289
|
-
const parsed = new URL(src);
|
|
290
|
-
if ((parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1") && parsed.pathname.startsWith("/uploads/")) {
|
|
291
|
-
const cleanRel = decodeURIComponent(parsed.pathname).replace(/^\/+/, "");
|
|
292
|
-
const fullPath = path.resolve(publicDir, cleanRel);
|
|
293
|
-
if (fs.existsSync(fullPath)) {
|
|
294
|
-
const buffer = await fs.promises.readFile(fullPath);
|
|
295
|
-
return { buffer, mime: "image/jpeg" };
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
const res = await fetch(src);
|
|
299
|
-
if (!res.ok) {
|
|
300
|
-
throw new Error(`Failed to fetch remote image (${res.status})`);
|
|
301
|
-
}
|
|
302
|
-
const contentType = res.headers.get("content-type") || "image/jpeg";
|
|
303
|
-
const arr = await res.arrayBuffer();
|
|
304
|
-
return { buffer: Buffer.from(arr), mime: contentType };
|
|
305
|
-
}
|
|
306
|
-
throw new Error("Unsupported image source URL");
|
|
307
|
-
}
|
|
308
1230
|
const ciImageController = ({ strapi }) => ({
|
|
309
1231
|
/**
|
|
310
1232
|
* GET /api/content-input/image & GET /content-input/image
|
|
311
|
-
*
|
|
1233
|
+
* Generates `ci-optimized` WebP variants via sharp, uploads to Strapi's Upload Provider (CDN),
|
|
1234
|
+
* persists in `plugin::upload.file.formats`, and issues a 302 redirect when a remote CDN URL is available
|
|
1235
|
+
* (with local byte-stream fallback in local-only environments).
|
|
312
1236
|
*/
|
|
313
1237
|
async processImage(ctx) {
|
|
314
1238
|
try {
|
|
@@ -317,16 +1241,96 @@ const ciImageController = ({ strapi }) => ({
|
|
|
317
1241
|
if (!src) {
|
|
318
1242
|
return ctx.badRequest("Missing src parameter");
|
|
319
1243
|
}
|
|
320
|
-
const
|
|
321
|
-
const
|
|
322
|
-
const
|
|
1244
|
+
const rawProc = String(query.process || "auto").trim().toLowerCase();
|
|
1245
|
+
const processMode = rawProc === "fit" ? "fit" : rawProc === "widen" ? "widen" : "auto";
|
|
1246
|
+
const w = Math.min(
|
|
1247
|
+
3840,
|
|
1248
|
+
Math.max(0, parseInt(String(query.w || query.cWidth || "0"), 10) || 0)
|
|
1249
|
+
);
|
|
1250
|
+
const h = Math.min(
|
|
1251
|
+
3840,
|
|
1252
|
+
Math.max(0, parseInt(String(query.h || query.cHeight || "0"), 10) || 0)
|
|
1253
|
+
);
|
|
323
1254
|
const q = Math.min(100, Math.max(20, parseInt(String(query.q || "85"), 10) || 85));
|
|
324
1255
|
const rotate = parseInt(String(query.rotate || "0"), 10) || 0;
|
|
325
1256
|
const cx = parseInt(String(query.x || "0"), 10) || 0;
|
|
326
1257
|
const cy = parseInt(String(query.y || "0"), 10) || 0;
|
|
327
1258
|
const cw = parseInt(String(query.cw || "0"), 10) || 0;
|
|
328
1259
|
const ch = parseInt(String(query.ch || "0"), 10) || 0;
|
|
329
|
-
const requestedFormat = String(query.format || "").toLowerCase();
|
|
1260
|
+
const requestedFormat = String(query.format || "").trim().toLowerCase();
|
|
1261
|
+
const acceptHeader = String(ctx.req?.headers?.accept || "");
|
|
1262
|
+
const wantsJson = query.json === "1" || query.json === "true" || acceptHeader.includes("application/json");
|
|
1263
|
+
const forceNoRedirect = query.redirect === "0" || query.redirect === "false" || query.proxy === "1" || query.proxy === "true";
|
|
1264
|
+
const forceRedirect = query.redirect === "1" || query.redirect === "true";
|
|
1265
|
+
const cfg = getVariantConfig(strapi);
|
|
1266
|
+
if (cw <= 0 && ch <= 0) {
|
|
1267
|
+
const existingFile = await findUploadFileForAsset(strapi, src);
|
|
1268
|
+
if (existingFile && existingFile.id) {
|
|
1269
|
+
if (!isOptimizableRasterImage(existingFile.mime, existingFile.ext || existingFile.url)) {
|
|
1270
|
+
const directUrl = existingFile.url;
|
|
1271
|
+
if (wantsJson) {
|
|
1272
|
+
ctx.body = { url: directUrl, formatKey: null };
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
if (!forceNoRedirect && directUrl && (cfg.redirectProxyToCdn && isAbsoluteHttpUrl(directUrl) || forceRedirect)) {
|
|
1276
|
+
ctx.set("Cache-Control", "public, max-age=86400");
|
|
1277
|
+
ctx.set("Access-Control-Allow-Origin", "*");
|
|
1278
|
+
ctx.status = 302;
|
|
1279
|
+
ctx.redirect(directUrl);
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
} else {
|
|
1283
|
+
const effW2 = w > 0 ? w : processMode === "auto" ? 1920 : 0;
|
|
1284
|
+
const effH2 = processMode === "fit" ? h : 0;
|
|
1285
|
+
if (effW2 > 0 || effH2 > 0) {
|
|
1286
|
+
const variantRes = await ensureMediaVariant(strapi, existingFile, {
|
|
1287
|
+
processMode,
|
|
1288
|
+
w: effW2,
|
|
1289
|
+
h: effH2,
|
|
1290
|
+
q,
|
|
1291
|
+
rotate,
|
|
1292
|
+
requestedFormat: requestedFormat || void 0
|
|
1293
|
+
});
|
|
1294
|
+
const providerUrl = variantRes.formatEntry?.url;
|
|
1295
|
+
if (providerUrl) {
|
|
1296
|
+
if (wantsJson) {
|
|
1297
|
+
ctx.body = {
|
|
1298
|
+
url: providerUrl,
|
|
1299
|
+
formatKey: variantRes.formatKey
|
|
1300
|
+
};
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
if (!forceNoRedirect && (cfg.redirectProxyToCdn && isAbsoluteHttpUrl(providerUrl) || forceRedirect)) {
|
|
1304
|
+
ctx.set("Cache-Control", "public, max-age=86400");
|
|
1305
|
+
ctx.set("Access-Control-Allow-Origin", "*");
|
|
1306
|
+
ctx.set("X-Content-Input-CDN-Url", providerUrl);
|
|
1307
|
+
ctx.status = 302;
|
|
1308
|
+
ctx.redirect(providerUrl);
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
try {
|
|
1312
|
+
const localVariant = await loadSourceBuffer(strapi, providerUrl);
|
|
1313
|
+
const etagLocal = `"ci-${variantRes.formatKey}-${existingFile.hash || existingFile.id}"`;
|
|
1314
|
+
if (ctx.req?.headers?.["if-none-match"] === etagLocal) {
|
|
1315
|
+
ctx.status = 304;
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
const resolvedMime = variantRes.formatEntry?.mime || localVariant.mime || "image/webp";
|
|
1319
|
+
ctx.body = localVariant.buffer;
|
|
1320
|
+
ctx.type = resolvedMime;
|
|
1321
|
+
ctx.set("Content-Type", resolvedMime);
|
|
1322
|
+
ctx.set("Cache-Control", "public, max-age=31536000, immutable");
|
|
1323
|
+
ctx.set("ETag", etagLocal);
|
|
1324
|
+
ctx.set("Access-Control-Allow-Origin", "*");
|
|
1325
|
+
ctx.set("X-Content-Input-CDN-Url", providerUrl);
|
|
1326
|
+
return;
|
|
1327
|
+
} catch {
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
330
1334
|
const cacheKeyRaw = JSON.stringify({
|
|
331
1335
|
src,
|
|
332
1336
|
processMode,
|
|
@@ -338,11 +1342,11 @@ const ciImageController = ({ strapi }) => ({
|
|
|
338
1342
|
cy,
|
|
339
1343
|
cw,
|
|
340
1344
|
ch,
|
|
341
|
-
requestedFormat
|
|
1345
|
+
requestedFormat: requestedFormat || cfg.defaultFormat
|
|
342
1346
|
});
|
|
343
1347
|
const hash = crypto.createHash("sha1").update(cacheKeyRaw).digest("hex");
|
|
344
1348
|
const etag = `"ci-${hash}"`;
|
|
345
|
-
if (ctx.req
|
|
1349
|
+
if (!wantsJson && ctx.req?.headers?.["if-none-match"] === etag) {
|
|
346
1350
|
ctx.status = 304;
|
|
347
1351
|
return;
|
|
348
1352
|
}
|
|
@@ -351,138 +1355,112 @@ const ciImageController = ({ strapi }) => ({
|
|
|
351
1355
|
const binPath = path.join(cacheDir, `${hash}.bin`);
|
|
352
1356
|
if (fs.existsSync(metaPath) && fs.existsSync(binPath)) {
|
|
353
1357
|
const meta = JSON.parse(await fs.promises.readFile(metaPath, "utf8"));
|
|
1358
|
+
if (meta.providerUrl) {
|
|
1359
|
+
if (wantsJson) {
|
|
1360
|
+
ctx.body = { url: meta.providerUrl, formatKey: meta.formatKey || null };
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
if (!forceNoRedirect && (cfg.redirectProxyToCdn && isAbsoluteHttpUrl(meta.providerUrl) || forceRedirect)) {
|
|
1364
|
+
ctx.set("Cache-Control", "public, max-age=86400");
|
|
1365
|
+
ctx.set("Access-Control-Allow-Origin", "*");
|
|
1366
|
+
ctx.set("X-Content-Input-CDN-Url", meta.providerUrl);
|
|
1367
|
+
ctx.status = 302;
|
|
1368
|
+
ctx.redirect(meta.providerUrl);
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
354
1372
|
const cachedBuffer = await fs.promises.readFile(binPath);
|
|
355
|
-
|
|
1373
|
+
const cachedMime = meta.contentType || "image/webp";
|
|
1374
|
+
ctx.body = cachedBuffer;
|
|
1375
|
+
ctx.type = cachedMime;
|
|
1376
|
+
ctx.set("Content-Type", cachedMime);
|
|
356
1377
|
ctx.set("Cache-Control", "public, max-age=31536000, immutable");
|
|
357
1378
|
ctx.set("ETag", etag);
|
|
358
1379
|
ctx.set("Access-Control-Allow-Origin", "*");
|
|
359
|
-
ctx.body = cachedBuffer;
|
|
360
1380
|
return;
|
|
361
1381
|
}
|
|
362
1382
|
const { buffer: sourceBuffer, mime: sourceMime } = await loadSourceBuffer(strapi, src);
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
position: "centre",
|
|
380
|
-
withoutEnlargement: false
|
|
381
|
-
});
|
|
382
|
-
} else if (processMode === "widen" && w > 0) {
|
|
383
|
-
pipeline = pipeline.resize(w, null, {
|
|
384
|
-
fit: "inside",
|
|
385
|
-
withoutEnlargement: false
|
|
386
|
-
});
|
|
387
|
-
} else if (w > 0 || h > 0) {
|
|
388
|
-
pipeline = pipeline.resize(w || null, h || null, {
|
|
389
|
-
fit: "inside",
|
|
390
|
-
withoutEnlargement: true
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
let outContentType = sourceMime;
|
|
394
|
-
if (requestedFormat === "webp" || sourceMime === "image/webp") {
|
|
395
|
-
pipeline = pipeline.webp({ quality: q });
|
|
396
|
-
outContentType = "image/webp";
|
|
397
|
-
} else if (requestedFormat === "avif" || sourceMime === "image/avif") {
|
|
398
|
-
pipeline = pipeline.avif({ quality: q });
|
|
399
|
-
outContentType = "image/avif";
|
|
400
|
-
} else if (requestedFormat === "png" || sourceMime === "image/png") {
|
|
401
|
-
pipeline = pipeline.png({ quality: q });
|
|
402
|
-
outContentType = "image/png";
|
|
403
|
-
} else {
|
|
404
|
-
pipeline = pipeline.jpeg({ quality: q, mozjpeg: true });
|
|
405
|
-
outContentType = "image/jpeg";
|
|
406
|
-
}
|
|
407
|
-
const outputBuffer = await pipeline.toBuffer();
|
|
408
|
-
let providerUrl;
|
|
409
|
-
try {
|
|
410
|
-
const cleanSrc = src.split("?")[0];
|
|
411
|
-
const existingFile = await strapi.db.query("plugin::upload.file").findOne({
|
|
412
|
-
where: { url: cleanSrc }
|
|
413
|
-
});
|
|
414
|
-
if (existingFile && existingFile.id) {
|
|
415
|
-
const formatKey = `ci_${processMode}_${w}x${h}${rotate ? `_r${rotate}` : ""}`;
|
|
416
|
-
const existingFormat = existingFile.formats?.[formatKey];
|
|
417
|
-
if (existingFormat?.url) {
|
|
418
|
-
providerUrl = existingFormat.url;
|
|
419
|
-
} else {
|
|
420
|
-
const outMeta = await sharp(outputBuffer).metadata();
|
|
421
|
-
const ext = outContentType === "image/png" ? ".png" : outContentType === "image/webp" ? ".webp" : outContentType === "image/avif" ? ".avif" : ".jpg";
|
|
422
|
-
const variantHash = `${formatKey}_${existingFile.hash || hash.slice(0, 10)}`;
|
|
423
|
-
const variantName = `${formatKey}_${existingFile.name || "image"}`;
|
|
424
|
-
const tmpVariantPath = path.join(os.tmpdir(), `${variantHash}${ext}`);
|
|
425
|
-
await fs.promises.writeFile(tmpVariantPath, outputBuffer);
|
|
426
|
-
try {
|
|
427
|
-
const variantFile = {
|
|
428
|
-
name: variantName,
|
|
429
|
-
hash: variantHash,
|
|
430
|
-
ext,
|
|
431
|
-
mime: outContentType,
|
|
432
|
-
filepath: tmpVariantPath,
|
|
433
|
-
path: existingFile.path || null,
|
|
434
|
-
getStream: () => fs.createReadStream(tmpVariantPath),
|
|
435
|
-
width: outMeta.width || w || void 0,
|
|
436
|
-
height: outMeta.height || h || void 0,
|
|
437
|
-
size: Math.round(outputBuffer.length / 1e3 * 100) / 100,
|
|
438
|
-
sizeInBytes: outputBuffer.length
|
|
439
|
-
};
|
|
440
|
-
const providerService = strapi.plugin("upload").service("provider");
|
|
441
|
-
if (providerService && typeof providerService.upload === "function") {
|
|
442
|
-
await providerService.upload(variantFile);
|
|
443
|
-
providerUrl = variantFile.url;
|
|
444
|
-
const { filepath: _fp, getStream: _gs, ...serializableFormat } = variantFile;
|
|
445
|
-
const nextFormats = {
|
|
446
|
-
...existingFile.formats || {},
|
|
447
|
-
[formatKey]: serializableFormat
|
|
448
|
-
};
|
|
449
|
-
await strapi.db.query("plugin::upload.file").update({
|
|
450
|
-
where: { id: existingFile.id },
|
|
451
|
-
data: { formats: nextFormats }
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
} finally {
|
|
455
|
-
await fs.promises.rm(tmpVariantPath, { force: true }).catch(() => void 0);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
} catch {
|
|
460
|
-
}
|
|
461
|
-
await fs.promises.writeFile(binPath, outputBuffer);
|
|
1383
|
+
const effW = w > 0 ? w : processMode === "auto" ? 1920 : 0;
|
|
1384
|
+
const effH = processMode === "fit" ? h : 0;
|
|
1385
|
+
const rendered = await renderSharpVariantBuffer(sourceBuffer, sourceMime, {
|
|
1386
|
+
processMode,
|
|
1387
|
+
w: effW,
|
|
1388
|
+
h: effH,
|
|
1389
|
+
q,
|
|
1390
|
+
rotate,
|
|
1391
|
+
cx,
|
|
1392
|
+
cy,
|
|
1393
|
+
cw,
|
|
1394
|
+
ch,
|
|
1395
|
+
requestedFormat: requestedFormat || void 0,
|
|
1396
|
+
defaultFormat: cfg.defaultFormat
|
|
1397
|
+
});
|
|
1398
|
+
await fs.promises.writeFile(binPath, rendered.buffer);
|
|
462
1399
|
await fs.promises.writeFile(
|
|
463
1400
|
metaPath,
|
|
464
1401
|
JSON.stringify({
|
|
465
|
-
contentType:
|
|
466
|
-
size:
|
|
467
|
-
providerUrl
|
|
1402
|
+
contentType: rendered.contentType,
|
|
1403
|
+
size: rendered.buffer.length
|
|
468
1404
|
})
|
|
469
1405
|
);
|
|
470
|
-
|
|
1406
|
+
if (wantsJson) {
|
|
1407
|
+
ctx.body = { url: src, formatKey: null };
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
ctx.body = rendered.buffer;
|
|
1411
|
+
ctx.type = rendered.contentType;
|
|
1412
|
+
ctx.set("Content-Type", rendered.contentType);
|
|
471
1413
|
ctx.set("Cache-Control", "public, max-age=31536000, immutable");
|
|
472
1414
|
ctx.set("ETag", etag);
|
|
473
1415
|
ctx.set("Access-Control-Allow-Origin", "*");
|
|
474
|
-
if (providerUrl) {
|
|
475
|
-
ctx.set("X-Content-Input-CDN-Url", providerUrl);
|
|
476
|
-
}
|
|
477
|
-
ctx.body = outputBuffer;
|
|
478
1416
|
} catch (err) {
|
|
479
1417
|
ctx.throw(400, err?.message || "Image processing error");
|
|
480
1418
|
}
|
|
481
1419
|
},
|
|
1420
|
+
/**
|
|
1421
|
+
* POST /content-input/media/optimize
|
|
1422
|
+
* Eagerly optimizes one or multiple selected/uploaded Media Library assets into `ci-optimized/*.webp`
|
|
1423
|
+
* on the configured Upload Provider (CDN) and returns enriched CIMediaAsset object(s) with `formats` & `optimized_url`.
|
|
1424
|
+
*/
|
|
1425
|
+
async optimizeMedia(ctx) {
|
|
1426
|
+
try {
|
|
1427
|
+
const body = ctx.request.body || {};
|
|
1428
|
+
const imageSettings = body.imageSettings || null;
|
|
1429
|
+
const defaultAutoMaxW = Number(body.defaultAutoMaxW) || 1920;
|
|
1430
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
1431
|
+
if (Array.isArray(body.assets)) {
|
|
1432
|
+
const enrichedList = [];
|
|
1433
|
+
for (const item of body.assets) {
|
|
1434
|
+
enrichedList.push(
|
|
1435
|
+
await enrichMediaAssetNode(strapi, item, {
|
|
1436
|
+
imageSettings,
|
|
1437
|
+
defaultAutoMaxW,
|
|
1438
|
+
fileCache
|
|
1439
|
+
})
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
ctx.body = { data: enrichedList };
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
if (body.asset) {
|
|
1446
|
+
const enriched = await enrichMediaAssetNode(strapi, body.asset, {
|
|
1447
|
+
imageSettings,
|
|
1448
|
+
defaultAutoMaxW,
|
|
1449
|
+
fileCache
|
|
1450
|
+
});
|
|
1451
|
+
ctx.body = { data: enriched };
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
return ctx.badRequest("asset or assets is required");
|
|
1455
|
+
} catch (err) {
|
|
1456
|
+
ctx.throw(500, err?.message || "Failed to optimize media asset");
|
|
1457
|
+
}
|
|
1458
|
+
},
|
|
482
1459
|
/**
|
|
483
1460
|
* POST /content-input/media/crop
|
|
484
1461
|
* Interactive crop & rotate using sharp on the backend (works seamlessly with local disk AND remote CDNs).
|
|
485
|
-
* Supports mode: 'replace' (crops original asset in Media Library
|
|
1462
|
+
* Supports mode: 'replace' (crops original asset in Media Library & refreshes ci-optimized variants)
|
|
1463
|
+
* or 'duplicate' (saves as new asset).
|
|
486
1464
|
*/
|
|
487
1465
|
async cropMedia(ctx) {
|
|
488
1466
|
const tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "ci-crop-"));
|
|
@@ -538,7 +1516,7 @@ const ciImageController = ({ strapi }) => ({
|
|
|
538
1516
|
if (ext === ".png" || mime === "image/png") {
|
|
539
1517
|
pipeline = pipeline.png({ quality: 92 });
|
|
540
1518
|
} else if (ext === ".webp" || mime === "image/webp") {
|
|
541
|
-
pipeline = pipeline.webp({ quality: 90 });
|
|
1519
|
+
pipeline = pipeline.webp({ quality: 90, alphaQuality: 100 });
|
|
542
1520
|
} else {
|
|
543
1521
|
pipeline = pipeline.jpeg({ quality: 90, mozjpeg: true });
|
|
544
1522
|
}
|
|
@@ -547,6 +1525,9 @@ const ciImageController = ({ strapi }) => ({
|
|
|
547
1525
|
const targetFileName = mode === "duplicate" ? `${body.name || `${baseName}-cropped`}${ext.startsWith(".") ? ext : `.${ext}`}` : existingFile.name || `${baseName}${ext}`;
|
|
548
1526
|
const tmpFilePath = path.join(tmpDir, targetFileName);
|
|
549
1527
|
await fs.promises.writeFile(tmpFilePath, croppedBuffer);
|
|
1528
|
+
if (mode === "replace") {
|
|
1529
|
+
await clearGeneratedCiVariantsForFile(strapi, existingFile);
|
|
1530
|
+
}
|
|
550
1531
|
const uploadService = strapi.plugin("upload").service("upload");
|
|
551
1532
|
const fileInfo = {
|
|
552
1533
|
name: targetFileName,
|
|
@@ -582,6 +1563,17 @@ const ciImageController = ({ strapi }) => ({
|
|
|
582
1563
|
);
|
|
583
1564
|
resultFile = Array.isArray(uploaded) ? uploaded[0] : uploaded;
|
|
584
1565
|
}
|
|
1566
|
+
if (resultFile?.id) {
|
|
1567
|
+
try {
|
|
1568
|
+
const freshRes = await ensureMediaVariant(strapi, resultFile, {
|
|
1569
|
+
processMode: "auto",
|
|
1570
|
+
w: 1920,
|
|
1571
|
+
h: 0
|
|
1572
|
+
});
|
|
1573
|
+
resultFile = freshRes.updatedFile || resultFile;
|
|
1574
|
+
} catch {
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
585
1577
|
ctx.body = { data: resultFile };
|
|
586
1578
|
} catch (err) {
|
|
587
1579
|
ctx.throw(500, err?.message || "Failed to crop media asset");
|
|
@@ -753,9 +1745,8 @@ const ciFormController = ({ strapi }) => ({
|
|
|
753
1745
|
const { id } = ctx.params;
|
|
754
1746
|
const rawBody = ctx.request.body || {};
|
|
755
1747
|
const payload = rawBody && typeof rawBody.data === "object" && !Array.isArray(rawBody.data) && Object.keys(rawBody).length === 1 ? rawBody.data : rawBody;
|
|
756
|
-
const
|
|
757
|
-
const
|
|
758
|
-
const inferredLocale = (queryLocale || acceptLang || "tr").toLowerCase();
|
|
1748
|
+
const queryLocale = String(ctx.query?.locale || payload?._locale || "").trim();
|
|
1749
|
+
const inferredLocale = (queryLocale || "en").toLowerCase();
|
|
759
1750
|
const ip = String(ctx.request.headers?.["x-forwarded-for"] || "").split(",")[0].trim() || ctx.request.ip || "";
|
|
760
1751
|
const userAgent = String(ctx.request.headers?.["user-agent"] || "");
|
|
761
1752
|
const result = await strapi.plugin("content-input").service("ci-form").submitForm(id, payload, {
|
|
@@ -863,7 +1854,7 @@ const ciSurveyController = ({ strapi }) => ({
|
|
|
863
1854
|
const payload = rawBody && typeof rawBody.data === "object" && !Array.isArray(rawBody.data) && Object.keys(rawBody).length === 1 ? rawBody.data : rawBody;
|
|
864
1855
|
const acceptLang = String(ctx.request.headers?.["accept-language"] || "").split(",")[0].split(";")[0].trim();
|
|
865
1856
|
const queryLocale = String(ctx.query?.locale || "").trim();
|
|
866
|
-
const inferredLocale = (queryLocale || acceptLang || "
|
|
1857
|
+
const inferredLocale = (queryLocale || acceptLang || "en").toLowerCase();
|
|
867
1858
|
const ip = String(ctx.request.headers?.["x-forwarded-for"] || "").split(",")[0].trim() || ctx.request.ip || "";
|
|
868
1859
|
const userAgent = String(ctx.request.headers?.["user-agent"] || "");
|
|
869
1860
|
const result = await strapi.plugin("content-input").service("ci-survey").submitSurvey(id, payload, {
|
|
@@ -918,7 +1909,7 @@ const ciSurveyController = ({ strapi }) => ({
|
|
|
918
1909
|
try {
|
|
919
1910
|
const { id } = ctx.params;
|
|
920
1911
|
const format = String(ctx.query?.format || "csv").toLowerCase() === "json" ? "json" : "csv";
|
|
921
|
-
const locale = String(ctx.query?.locale || "
|
|
1912
|
+
const locale = String(ctx.query?.locale || "en").trim();
|
|
922
1913
|
const from = ctx.query?.from ? String(ctx.query.from) : void 0;
|
|
923
1914
|
const to = ctx.query?.to ? String(ctx.query.to) : void 0;
|
|
924
1915
|
const exported = await strapi.plugin("content-input").service("ci-survey").exportResponses(id, { format, locale, from, to });
|
|
@@ -942,12 +1933,112 @@ const ciSurveyController = ({ strapi }) => ({
|
|
|
942
1933
|
}
|
|
943
1934
|
}
|
|
944
1935
|
});
|
|
1936
|
+
const ciColorController = ({ strapi }) => ({
|
|
1937
|
+
async indexAdmin(ctx) {
|
|
1938
|
+
try {
|
|
1939
|
+
const res = await strapi.plugin("content-input").service("ci-color").findAll();
|
|
1940
|
+
ctx.body = res;
|
|
1941
|
+
} catch (err) {
|
|
1942
|
+
ctx.throw(500, err);
|
|
1943
|
+
}
|
|
1944
|
+
},
|
|
1945
|
+
async activePublic(ctx) {
|
|
1946
|
+
try {
|
|
1947
|
+
const slug = ctx.query?.slug ? String(ctx.query.slug) : void 0;
|
|
1948
|
+
const res = await strapi.plugin("content-input").service("ci-color").findActivePublic(slug);
|
|
1949
|
+
ctx.body = res;
|
|
1950
|
+
} catch (err) {
|
|
1951
|
+
ctx.throw(500, err);
|
|
1952
|
+
}
|
|
1953
|
+
},
|
|
1954
|
+
async save(ctx) {
|
|
1955
|
+
try {
|
|
1956
|
+
const body = ctx.request.body || {};
|
|
1957
|
+
const res = await strapi.plugin("content-input").service("ci-color").save(body);
|
|
1958
|
+
ctx.body = res;
|
|
1959
|
+
} catch (err) {
|
|
1960
|
+
ctx.throw(500, err);
|
|
1961
|
+
}
|
|
1962
|
+
},
|
|
1963
|
+
async activate(ctx) {
|
|
1964
|
+
try {
|
|
1965
|
+
const { id } = ctx.params || {};
|
|
1966
|
+
const res = await strapi.plugin("content-input").service("ci-color").activate(id);
|
|
1967
|
+
if (!res) {
|
|
1968
|
+
return ctx.notFound("Color palette not found");
|
|
1969
|
+
}
|
|
1970
|
+
ctx.body = res;
|
|
1971
|
+
} catch (err) {
|
|
1972
|
+
ctx.throw(500, err);
|
|
1973
|
+
}
|
|
1974
|
+
},
|
|
1975
|
+
async quickToken(ctx) {
|
|
1976
|
+
try {
|
|
1977
|
+
const body = ctx.request.body || {};
|
|
1978
|
+
if (!body.value) {
|
|
1979
|
+
return ctx.badRequest("Color value (HEX or RGB/RGBA) is required");
|
|
1980
|
+
}
|
|
1981
|
+
const res = await strapi.plugin("content-input").service("ci-color").upsertQuickCustomToken({
|
|
1982
|
+
key: body.key || body.label || "customColor",
|
|
1983
|
+
label: body.label,
|
|
1984
|
+
labels: body.labels,
|
|
1985
|
+
value: body.value
|
|
1986
|
+
});
|
|
1987
|
+
ctx.body = res;
|
|
1988
|
+
} catch (err) {
|
|
1989
|
+
ctx.throw(500, err);
|
|
1990
|
+
}
|
|
1991
|
+
},
|
|
1992
|
+
async delete(ctx) {
|
|
1993
|
+
try {
|
|
1994
|
+
const { id } = ctx.params || {};
|
|
1995
|
+
const res = await strapi.plugin("content-input").service("ci-color").remove(id);
|
|
1996
|
+
ctx.body = res;
|
|
1997
|
+
} catch (err) {
|
|
1998
|
+
ctx.badRequest(err?.message || "Unable to delete palette");
|
|
1999
|
+
}
|
|
2000
|
+
},
|
|
2001
|
+
async dataTableCollection(ctx) {
|
|
2002
|
+
try {
|
|
2003
|
+
const { uid, limit, sort } = ctx.query || {};
|
|
2004
|
+
if (!uid) {
|
|
2005
|
+
return ctx.badRequest('Query parameter "uid" is required');
|
|
2006
|
+
}
|
|
2007
|
+
const res = await strapi.plugin("content-input").service("ci-color").queryCollectionForDataTable({
|
|
2008
|
+
uid: String(uid),
|
|
2009
|
+
limit: limit ? Number(limit) : 25,
|
|
2010
|
+
sort: sort ? String(sort) : "createdAt:desc"
|
|
2011
|
+
});
|
|
2012
|
+
ctx.body = { data: res };
|
|
2013
|
+
} catch (err) {
|
|
2014
|
+
ctx.throw(500, err);
|
|
2015
|
+
}
|
|
2016
|
+
},
|
|
2017
|
+
async entityCardsBatch(ctx) {
|
|
2018
|
+
try {
|
|
2019
|
+
const { uid, documentIds, limit } = ctx.query || {};
|
|
2020
|
+
if (!uid) {
|
|
2021
|
+
return ctx.badRequest('Query parameter "uid" is required');
|
|
2022
|
+
}
|
|
2023
|
+
const docList = typeof documentIds === "string" && documentIds.trim() ? documentIds.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
2024
|
+
const items = await strapi.plugin("content-input").service("ci-color").resolveEntityCardsBatch({
|
|
2025
|
+
uid: String(uid),
|
|
2026
|
+
documentIds: docList,
|
|
2027
|
+
limit: limit ? Number(limit) : 6
|
|
2028
|
+
});
|
|
2029
|
+
ctx.body = { data: items };
|
|
2030
|
+
} catch (err) {
|
|
2031
|
+
ctx.throw(500, err);
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
});
|
|
945
2035
|
const controllers = {
|
|
946
2036
|
"ci-template": ciTemplateController,
|
|
947
2037
|
"ci-menu": ciMenuController,
|
|
948
2038
|
"ci-image": ciImageController,
|
|
949
2039
|
"ci-form": ciFormController,
|
|
950
|
-
"ci-survey": ciSurveyController
|
|
2040
|
+
"ci-survey": ciSurveyController,
|
|
2041
|
+
"ci-color": ciColorController
|
|
951
2042
|
};
|
|
952
2043
|
const routes = {
|
|
953
2044
|
admin: {
|
|
@@ -978,57 +2069,113 @@ const routes = {
|
|
|
978
2069
|
}
|
|
979
2070
|
},
|
|
980
2071
|
{
|
|
981
|
-
method: "DELETE",
|
|
982
|
-
path: "/templates/:id",
|
|
983
|
-
handler: "ci-template.delete",
|
|
2072
|
+
method: "DELETE",
|
|
2073
|
+
path: "/templates/:id",
|
|
2074
|
+
handler: "ci-template.delete",
|
|
2075
|
+
config: {
|
|
2076
|
+
policies: []
|
|
2077
|
+
}
|
|
2078
|
+
},
|
|
2079
|
+
{
|
|
2080
|
+
method: "GET",
|
|
2081
|
+
path: "/menus",
|
|
2082
|
+
handler: "ci-menu.index",
|
|
2083
|
+
config: {
|
|
2084
|
+
policies: []
|
|
2085
|
+
}
|
|
2086
|
+
},
|
|
2087
|
+
{
|
|
2088
|
+
method: "POST",
|
|
2089
|
+
path: "/menus",
|
|
2090
|
+
handler: "ci-menu.save",
|
|
2091
|
+
config: {
|
|
2092
|
+
policies: []
|
|
2093
|
+
}
|
|
2094
|
+
},
|
|
2095
|
+
{
|
|
2096
|
+
method: "DELETE",
|
|
2097
|
+
path: "/menus/:id",
|
|
2098
|
+
handler: "ci-menu.delete",
|
|
2099
|
+
config: {
|
|
2100
|
+
policies: []
|
|
2101
|
+
}
|
|
2102
|
+
},
|
|
2103
|
+
{
|
|
2104
|
+
method: "GET",
|
|
2105
|
+
path: "/entity-types",
|
|
2106
|
+
handler: "ci-menu.entityTypes",
|
|
2107
|
+
config: {
|
|
2108
|
+
policies: []
|
|
2109
|
+
}
|
|
2110
|
+
},
|
|
2111
|
+
{
|
|
2112
|
+
method: "GET",
|
|
2113
|
+
path: "/entities",
|
|
2114
|
+
handler: "ci-menu.entities",
|
|
2115
|
+
config: {
|
|
2116
|
+
policies: []
|
|
2117
|
+
}
|
|
2118
|
+
},
|
|
2119
|
+
{
|
|
2120
|
+
method: "GET",
|
|
2121
|
+
path: "/entity-card",
|
|
2122
|
+
handler: "ci-form.entityCard",
|
|
2123
|
+
config: {
|
|
2124
|
+
policies: []
|
|
2125
|
+
}
|
|
2126
|
+
},
|
|
2127
|
+
{
|
|
2128
|
+
method: "GET",
|
|
2129
|
+
path: "/entity-cards",
|
|
2130
|
+
handler: "ci-color.entityCardsBatch",
|
|
984
2131
|
config: {
|
|
985
2132
|
policies: []
|
|
986
2133
|
}
|
|
987
2134
|
},
|
|
988
2135
|
{
|
|
989
2136
|
method: "GET",
|
|
990
|
-
path: "/
|
|
991
|
-
handler: "ci-
|
|
2137
|
+
path: "/data-table",
|
|
2138
|
+
handler: "ci-color.dataTableCollection",
|
|
992
2139
|
config: {
|
|
993
2140
|
policies: []
|
|
994
2141
|
}
|
|
995
2142
|
},
|
|
996
2143
|
{
|
|
997
|
-
method: "
|
|
998
|
-
path: "/
|
|
999
|
-
handler: "ci-
|
|
2144
|
+
method: "GET",
|
|
2145
|
+
path: "/color-codes",
|
|
2146
|
+
handler: "ci-color.indexAdmin",
|
|
1000
2147
|
config: {
|
|
1001
2148
|
policies: []
|
|
1002
2149
|
}
|
|
1003
2150
|
},
|
|
1004
2151
|
{
|
|
1005
|
-
method: "
|
|
1006
|
-
path: "/
|
|
1007
|
-
handler: "ci-
|
|
2152
|
+
method: "POST",
|
|
2153
|
+
path: "/color-codes",
|
|
2154
|
+
handler: "ci-color.save",
|
|
1008
2155
|
config: {
|
|
1009
2156
|
policies: []
|
|
1010
2157
|
}
|
|
1011
2158
|
},
|
|
1012
2159
|
{
|
|
1013
|
-
method: "
|
|
1014
|
-
path: "/
|
|
1015
|
-
handler: "ci-
|
|
2160
|
+
method: "POST",
|
|
2161
|
+
path: "/color-codes/quick-token",
|
|
2162
|
+
handler: "ci-color.quickToken",
|
|
1016
2163
|
config: {
|
|
1017
2164
|
policies: []
|
|
1018
2165
|
}
|
|
1019
2166
|
},
|
|
1020
2167
|
{
|
|
1021
|
-
method: "
|
|
1022
|
-
path: "/
|
|
1023
|
-
handler: "ci-
|
|
2168
|
+
method: "POST",
|
|
2169
|
+
path: "/color-codes/:id/activate",
|
|
2170
|
+
handler: "ci-color.activate",
|
|
1024
2171
|
config: {
|
|
1025
2172
|
policies: []
|
|
1026
2173
|
}
|
|
1027
2174
|
},
|
|
1028
2175
|
{
|
|
1029
|
-
method: "
|
|
1030
|
-
path: "/
|
|
1031
|
-
handler: "ci-
|
|
2176
|
+
method: "DELETE",
|
|
2177
|
+
path: "/color-codes/:id",
|
|
2178
|
+
handler: "ci-color.delete",
|
|
1032
2179
|
config: {
|
|
1033
2180
|
policies: []
|
|
1034
2181
|
}
|
|
@@ -1153,6 +2300,14 @@ const routes = {
|
|
|
1153
2300
|
policies: []
|
|
1154
2301
|
}
|
|
1155
2302
|
},
|
|
2303
|
+
{
|
|
2304
|
+
method: "POST",
|
|
2305
|
+
path: "/media/optimize",
|
|
2306
|
+
handler: "ci-image.optimizeMedia",
|
|
2307
|
+
config: {
|
|
2308
|
+
policies: []
|
|
2309
|
+
}
|
|
2310
|
+
},
|
|
1156
2311
|
{
|
|
1157
2312
|
method: "POST",
|
|
1158
2313
|
path: "/media/crop",
|
|
@@ -1297,6 +2452,33 @@ const routes = {
|
|
|
1297
2452
|
auth: false,
|
|
1298
2453
|
policies: []
|
|
1299
2454
|
}
|
|
2455
|
+
},
|
|
2456
|
+
{
|
|
2457
|
+
method: "GET",
|
|
2458
|
+
path: "/entity-cards",
|
|
2459
|
+
handler: "ci-color.entityCardsBatch",
|
|
2460
|
+
config: {
|
|
2461
|
+
auth: false,
|
|
2462
|
+
policies: []
|
|
2463
|
+
}
|
|
2464
|
+
},
|
|
2465
|
+
{
|
|
2466
|
+
method: "GET",
|
|
2467
|
+
path: "/data-table",
|
|
2468
|
+
handler: "ci-color.dataTableCollection",
|
|
2469
|
+
config: {
|
|
2470
|
+
auth: false,
|
|
2471
|
+
policies: []
|
|
2472
|
+
}
|
|
2473
|
+
},
|
|
2474
|
+
{
|
|
2475
|
+
method: "GET",
|
|
2476
|
+
path: "/color-codes",
|
|
2477
|
+
handler: "ci-color.activePublic",
|
|
2478
|
+
config: {
|
|
2479
|
+
auth: false,
|
|
2480
|
+
policies: []
|
|
2481
|
+
}
|
|
1300
2482
|
}
|
|
1301
2483
|
]
|
|
1302
2484
|
}
|
|
@@ -1313,7 +2495,7 @@ const ciTemplateService = ({ strapi }) => ({
|
|
|
1313
2495
|
}));
|
|
1314
2496
|
},
|
|
1315
2497
|
async create(data) {
|
|
1316
|
-
const structure = Array.isArray(data.structure) ? data.structure : [data.structure];
|
|
2498
|
+
const structure = data.category === "card_design" ? data.structure : Array.isArray(data.structure) ? data.structure : [data.structure];
|
|
1317
2499
|
const created = await strapi.db.query(UID).create({
|
|
1318
2500
|
data: {
|
|
1319
2501
|
name: String(data.name || "").trim(),
|
|
@@ -1361,7 +2543,7 @@ function slugifyTR(text) {
|
|
|
1361
2543
|
}
|
|
1362
2544
|
const DEFAULT_SEED_MENUS = [
|
|
1363
2545
|
{
|
|
1364
|
-
name: "
|
|
2546
|
+
name: "Main Header Navigation",
|
|
1365
2547
|
slug: "main-header-menu",
|
|
1366
2548
|
mode: "horizontal",
|
|
1367
2549
|
options: {
|
|
@@ -1373,7 +2555,7 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1373
2555
|
items: [
|
|
1374
2556
|
{
|
|
1375
2557
|
_uId: "m_home",
|
|
1376
|
-
title: "Ana Sayfa",
|
|
2558
|
+
title: { en: "Home", tr: "Ana Sayfa" },
|
|
1377
2559
|
url: "/",
|
|
1378
2560
|
type: "custom",
|
|
1379
2561
|
target: "_self",
|
|
@@ -1382,31 +2564,31 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1382
2564
|
},
|
|
1383
2565
|
{
|
|
1384
2566
|
_uId: "m_corp",
|
|
1385
|
-
title: "Kurumsal",
|
|
1386
|
-
url: "/
|
|
2567
|
+
title: { en: "Company", tr: "Kurumsal" },
|
|
2568
|
+
url: "/company",
|
|
1387
2569
|
type: "custom",
|
|
1388
2570
|
target: "_self",
|
|
1389
2571
|
icon: "business",
|
|
1390
2572
|
children: [
|
|
1391
2573
|
{
|
|
1392
2574
|
_uId: "m_about",
|
|
1393
|
-
title: "Hakkımızda",
|
|
1394
|
-
url: "/
|
|
2575
|
+
title: { en: "About Us", tr: "Hakkımızda" },
|
|
2576
|
+
url: "/company/about",
|
|
1395
2577
|
type: "custom",
|
|
1396
2578
|
target: "_self",
|
|
1397
2579
|
children: []
|
|
1398
2580
|
},
|
|
1399
2581
|
{
|
|
1400
2582
|
_uId: "m_vision",
|
|
1401
|
-
title: "Vizyon & Misyon",
|
|
1402
|
-
url: "/
|
|
2583
|
+
title: { en: "Vision & Mission", tr: "Vizyon & Misyon" },
|
|
2584
|
+
url: "/company/vision-mission",
|
|
1403
2585
|
type: "custom",
|
|
1404
2586
|
target: "_self",
|
|
1405
2587
|
children: [
|
|
1406
2588
|
{
|
|
1407
2589
|
_uId: "m_values",
|
|
1408
|
-
title: "Değerlerimiz & İlkelerimiz",
|
|
1409
|
-
url: "/
|
|
2590
|
+
title: { en: "Core Values & Principles", tr: "Değerlerimiz & İlkelerimiz" },
|
|
2591
|
+
url: "/company/values",
|
|
1410
2592
|
type: "custom",
|
|
1411
2593
|
target: "_self",
|
|
1412
2594
|
children: []
|
|
@@ -1415,8 +2597,8 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1415
2597
|
},
|
|
1416
2598
|
{
|
|
1417
2599
|
_uId: "m_board",
|
|
1418
|
-
title: "Yönetim Kurulu",
|
|
1419
|
-
url: "/
|
|
2600
|
+
title: { en: "Board of Directors", tr: "Yönetim Kurulu" },
|
|
2601
|
+
url: "/company/board",
|
|
1420
2602
|
type: "custom",
|
|
1421
2603
|
target: "_self",
|
|
1422
2604
|
children: []
|
|
@@ -1425,24 +2607,24 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1425
2607
|
},
|
|
1426
2608
|
{
|
|
1427
2609
|
_uId: "m_solutions",
|
|
1428
|
-
title: "Çözümlerimiz",
|
|
1429
|
-
url: "/
|
|
2610
|
+
title: { en: "Solutions", tr: "Çözümlerimiz" },
|
|
2611
|
+
url: "/solutions",
|
|
1430
2612
|
type: "custom",
|
|
1431
2613
|
target: "_self",
|
|
1432
2614
|
icon: "layers",
|
|
1433
2615
|
children: [
|
|
1434
2616
|
{
|
|
1435
2617
|
_uId: "m_sol_cms",
|
|
1436
|
-
title: "Kurumsal İçerik Yönetimi (CMS)",
|
|
1437
|
-
url: "/
|
|
2618
|
+
title: { en: "Enterprise Content Management (CMS)", tr: "Kurumsal İçerik Yönetimi (CMS)" },
|
|
2619
|
+
url: "/solutions/cms",
|
|
1438
2620
|
type: "custom",
|
|
1439
2621
|
target: "_self",
|
|
1440
2622
|
children: []
|
|
1441
2623
|
},
|
|
1442
2624
|
{
|
|
1443
2625
|
_uId: "m_sol_cloud",
|
|
1444
|
-
title: "Bulut & Mikroservis Mimarisi",
|
|
1445
|
-
url: "/
|
|
2626
|
+
title: { en: "Cloud & Microservice Architecture", tr: "Bulut & Mikroservis Mimarisi" },
|
|
2627
|
+
url: "/solutions/cloud",
|
|
1446
2628
|
type: "custom",
|
|
1447
2629
|
target: "_self",
|
|
1448
2630
|
children: []
|
|
@@ -1451,8 +2633,8 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1451
2633
|
},
|
|
1452
2634
|
{
|
|
1453
2635
|
_uId: "m_contact",
|
|
1454
|
-
title: "İletişim",
|
|
1455
|
-
url: "/
|
|
2636
|
+
title: { en: "Contact", tr: "İletişim" },
|
|
2637
|
+
url: "/contact",
|
|
1456
2638
|
type: "custom",
|
|
1457
2639
|
target: "_self",
|
|
1458
2640
|
icon: "mail",
|
|
@@ -1461,7 +2643,7 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1461
2643
|
]
|
|
1462
2644
|
},
|
|
1463
2645
|
{
|
|
1464
|
-
name: "
|
|
2646
|
+
name: "Corporate Sidebar Menu (Vertical Tree)",
|
|
1465
2647
|
slug: "corporate-sidebar-menu",
|
|
1466
2648
|
mode: "vertical",
|
|
1467
2649
|
options: {
|
|
@@ -1473,30 +2655,30 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1473
2655
|
items: [
|
|
1474
2656
|
{
|
|
1475
2657
|
_uId: "v_corp",
|
|
1476
|
-
title: "Kurumsal Bilgiler",
|
|
1477
|
-
url: "/
|
|
2658
|
+
title: { en: "Corporate Profile", tr: "Kurumsal Bilgiler" },
|
|
2659
|
+
url: "/company",
|
|
1478
2660
|
type: "custom",
|
|
1479
2661
|
target: "_self",
|
|
1480
2662
|
children: [
|
|
1481
2663
|
{
|
|
1482
2664
|
_uId: "v_history",
|
|
1483
|
-
title: "Tarihçemiz",
|
|
1484
|
-
url: "/
|
|
2665
|
+
title: { en: "Our History", tr: "Tarihçemiz" },
|
|
2666
|
+
url: "/company/history",
|
|
1485
2667
|
type: "custom",
|
|
1486
2668
|
target: "_self",
|
|
1487
2669
|
children: []
|
|
1488
2670
|
},
|
|
1489
2671
|
{
|
|
1490
2672
|
_uId: "v_quality",
|
|
1491
|
-
title: "Kalite Politikamız",
|
|
1492
|
-
url: "/
|
|
2673
|
+
title: { en: "Quality Policy", tr: "Kalite Politikamız" },
|
|
2674
|
+
url: "/company/quality",
|
|
1493
2675
|
type: "custom",
|
|
1494
2676
|
target: "_self",
|
|
1495
2677
|
children: [
|
|
1496
2678
|
{
|
|
1497
2679
|
_uId: "v_iso",
|
|
1498
|
-
title: "ISO 27001 & Sertifikalar",
|
|
1499
|
-
url: "/
|
|
2680
|
+
title: { en: "ISO 27001 & Certifications", tr: "ISO 27001 & Sertifikalar" },
|
|
2681
|
+
url: "/company/quality/certifications",
|
|
1500
2682
|
type: "custom",
|
|
1501
2683
|
target: "_self",
|
|
1502
2684
|
children: []
|
|
@@ -1507,8 +2689,8 @@ const DEFAULT_SEED_MENUS = [
|
|
|
1507
2689
|
},
|
|
1508
2690
|
{
|
|
1509
2691
|
_uId: "v_career",
|
|
1510
|
-
title: "İnsan Kaynakları & Kariyer",
|
|
1511
|
-
url: "/
|
|
2692
|
+
title: { en: "Careers & Human Resources", tr: "İnsan Kaynakları & Kariyer" },
|
|
2693
|
+
url: "/careers",
|
|
1512
2694
|
type: "custom",
|
|
1513
2695
|
target: "_self",
|
|
1514
2696
|
children: []
|
|
@@ -1535,7 +2717,7 @@ const ciMenuService = ({ strapi }) => ({
|
|
|
1535
2717
|
}));
|
|
1536
2718
|
},
|
|
1537
2719
|
async save(data) {
|
|
1538
|
-
const cleanName = String(data.name || "
|
|
2720
|
+
const cleanName = String(data.name || "Menu").trim();
|
|
1539
2721
|
const cleanSlug = String(data.slug || slugifyTR(cleanName) || `menu-${Date.now()}`).trim();
|
|
1540
2722
|
const cleanMode = data.mode === "vertical" ? "vertical" : "horizontal";
|
|
1541
2723
|
const cleanItems = Array.isArray(data.items) ? data.items : [];
|
|
@@ -1773,13 +2955,13 @@ function splitValidationRules(validationStr) {
|
|
|
1773
2955
|
}
|
|
1774
2956
|
return merged;
|
|
1775
2957
|
}
|
|
1776
|
-
function resolveLocalizedText(val, locale = "
|
|
2958
|
+
function resolveLocalizedText(val, locale = "en", fallback = "") {
|
|
1777
2959
|
if (!val) return fallback;
|
|
1778
2960
|
if (typeof val === "string") return val;
|
|
1779
2961
|
if (typeof val === "object") {
|
|
1780
|
-
const code = String(locale || "
|
|
2962
|
+
const code = String(locale || "en").trim();
|
|
1781
2963
|
const shortCode = code.split(/[-_]/)[0];
|
|
1782
|
-
return val[code] || val[shortCode] || val.
|
|
2964
|
+
return val[code] || val[shortCode] || val.en || val.tr || Object.values(val).find((v) => typeof v === "string" && v.trim() !== "") || fallback;
|
|
1783
2965
|
}
|
|
1784
2966
|
return fallback;
|
|
1785
2967
|
}
|
|
@@ -1794,7 +2976,7 @@ function isEmptyFieldValue(value) {
|
|
|
1794
2976
|
function msg(locale, trText, enText) {
|
|
1795
2977
|
return String(locale || "").toLowerCase().startsWith("tr") ? trText : enText;
|
|
1796
2978
|
}
|
|
1797
|
-
function validateSingleField(value, field, allData = {}, locale = "
|
|
2979
|
+
function validateSingleField(value, field, allData = {}, locale = "en") {
|
|
1798
2980
|
const errors = [];
|
|
1799
2981
|
const rawValidation = typeof field.validation === "object" && field.validation !== null ? resolveLocalizedText(field.validation, locale, "") : String(field.validation || "");
|
|
1800
2982
|
const rules = splitValidationRules(rawValidation);
|
|
@@ -2041,7 +3223,7 @@ function validateSingleField(value, field, allData = {}, locale = "tr") {
|
|
|
2041
3223
|
}
|
|
2042
3224
|
return errors;
|
|
2043
3225
|
}
|
|
2044
|
-
function validateFormSubmission(fieldsMap, payload, locale = "
|
|
3226
|
+
function validateFormSubmission(fieldsMap, payload, locale = "en") {
|
|
2045
3227
|
const errors = {};
|
|
2046
3228
|
const data = payload || {};
|
|
2047
3229
|
for (const [key, fieldDef] of Object.entries(fieldsMap || {})) {
|
|
@@ -2095,25 +3277,28 @@ function escapeHtml(input) {
|
|
|
2095
3277
|
const str = input === null || input === void 0 ? "" : String(input);
|
|
2096
3278
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2097
3279
|
}
|
|
2098
|
-
function formatFieldValue(val) {
|
|
3280
|
+
function formatFieldValue(val, locale = "en") {
|
|
2099
3281
|
if (val === null || val === void 0 || val === "") return "-";
|
|
2100
3282
|
if (Array.isArray(val)) return val.join(", ");
|
|
2101
|
-
if (typeof val === "boolean")
|
|
3283
|
+
if (typeof val === "boolean") {
|
|
3284
|
+
const tr = String(locale || "en").toLowerCase().startsWith("tr");
|
|
3285
|
+
return val ? tr ? "Evet" : "Yes" : tr ? "Hayır" : "No";
|
|
3286
|
+
}
|
|
2102
3287
|
if (typeof val === "object") return JSON.stringify(val);
|
|
2103
3288
|
return String(val);
|
|
2104
3289
|
}
|
|
2105
3290
|
function renderContentFormMailHtml(params) {
|
|
2106
3291
|
const { form, data, meta } = params;
|
|
2107
|
-
const locale = meta?.locale || "
|
|
3292
|
+
const locale = meta?.locale || "en";
|
|
2108
3293
|
const fields = form.fields || {};
|
|
2109
3294
|
const entries = Object.keys(fields).length > 0 ? Object.entries(fields).map(([key, def]) => ({
|
|
2110
3295
|
key,
|
|
2111
3296
|
label: resolveLocalizedText(def?.alias, locale, key),
|
|
2112
|
-
value: formatFieldValue(data[key])
|
|
3297
|
+
value: formatFieldValue(data[key], locale)
|
|
2113
3298
|
})) : Object.entries(data || {}).map(([key, val]) => ({
|
|
2114
3299
|
key,
|
|
2115
3300
|
label: key,
|
|
2116
|
-
value: formatFieldValue(val)
|
|
3301
|
+
value: formatFieldValue(val, locale)
|
|
2117
3302
|
}));
|
|
2118
3303
|
const rowsHtml = entries.map(
|
|
2119
3304
|
(item) => `
|
|
@@ -2179,6 +3364,46 @@ function parseFromAddress(rawFrom, rawName) {
|
|
|
2179
3364
|
const name = (rawName || fallbackName).trim();
|
|
2180
3365
|
return { email: trimmed, name, formatted: `"${name}" <${trimmed}>` };
|
|
2181
3366
|
}
|
|
3367
|
+
const mailtrapInboxCache = /* @__PURE__ */ new Map();
|
|
3368
|
+
async function discoverMailtrapSandboxInbox(rawToken) {
|
|
3369
|
+
const token = String(rawToken || "").trim();
|
|
3370
|
+
if (!token) return "";
|
|
3371
|
+
if (mailtrapInboxCache.has(token)) {
|
|
3372
|
+
return mailtrapInboxCache.get(token) || "";
|
|
3373
|
+
}
|
|
3374
|
+
try {
|
|
3375
|
+
const accRes = await fetch("https://mailtrap.io/api/accounts", {
|
|
3376
|
+
headers: {
|
|
3377
|
+
Authorization: `Bearer ${token}`,
|
|
3378
|
+
"Api-Token": token
|
|
3379
|
+
}
|
|
3380
|
+
});
|
|
3381
|
+
if (!accRes.ok) return "";
|
|
3382
|
+
const accounts = await accRes.json();
|
|
3383
|
+
const accountId = Array.isArray(accounts) && accounts[0]?.id ? accounts[0].id : null;
|
|
3384
|
+
if (!accountId) return "";
|
|
3385
|
+
const inbRes = await fetch(
|
|
3386
|
+
`https://mailtrap.io/api/accounts/${encodeURIComponent(String(accountId))}/inboxes`,
|
|
3387
|
+
{
|
|
3388
|
+
headers: {
|
|
3389
|
+
Authorization: `Bearer ${token}`,
|
|
3390
|
+
"Api-Token": token
|
|
3391
|
+
}
|
|
3392
|
+
}
|
|
3393
|
+
);
|
|
3394
|
+
if (!inbRes.ok) return "";
|
|
3395
|
+
const inboxes = await inbRes.json();
|
|
3396
|
+
if (!Array.isArray(inboxes) || inboxes.length === 0) return "";
|
|
3397
|
+
const activeInbox = inboxes.find((i) => i?.status === "active") || inboxes[0];
|
|
3398
|
+
const discoveredId = activeInbox?.id ? String(activeInbox.id) : "";
|
|
3399
|
+
if (discoveredId) {
|
|
3400
|
+
mailtrapInboxCache.set(token, discoveredId);
|
|
3401
|
+
}
|
|
3402
|
+
return discoveredId;
|
|
3403
|
+
} catch {
|
|
3404
|
+
return "";
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
2182
3407
|
async function sendDynamicFormMail(params) {
|
|
2183
3408
|
const { form, strapi } = params;
|
|
2184
3409
|
const cfg = form.mailConfig || {};
|
|
@@ -2206,7 +3431,8 @@ async function sendDynamicFormMail(params) {
|
|
|
2206
3431
|
cfg.from || process.env.MAIL_FROM,
|
|
2207
3432
|
cfg.fromName || process.env.MAIL_FROM_NAME
|
|
2208
3433
|
);
|
|
2209
|
-
const
|
|
3434
|
+
const isTr = String(params.meta?.locale || "en").toLowerCase().startsWith("tr");
|
|
3435
|
+
const subject = form.subject?.trim() || `${form.title} — ${isTr ? "Yeni Form Başvurusu" : "New Form Submission"}`;
|
|
2210
3436
|
const { html, text } = renderContentFormMailHtml(params);
|
|
2211
3437
|
let resolvedDriver = explicitDriver;
|
|
2212
3438
|
if (resolvedDriver === "auto") {
|
|
@@ -2218,11 +3444,17 @@ async function sendDynamicFormMail(params) {
|
|
|
2218
3444
|
try {
|
|
2219
3445
|
if (resolvedDriver === "mailtrap") {
|
|
2220
3446
|
if (mailtrapToken) {
|
|
2221
|
-
const
|
|
3447
|
+
const cleanToken = mailtrapToken.trim();
|
|
3448
|
+
let effectiveInboxId = mailtrapInboxId ? String(mailtrapInboxId).trim() : "";
|
|
3449
|
+
if (!effectiveInboxId) {
|
|
3450
|
+
effectiveInboxId = await discoverMailtrapSandboxInbox(cleanToken);
|
|
3451
|
+
}
|
|
3452
|
+
const endpoint = effectiveInboxId ? `https://sandbox.api.mailtrap.io/api/send/${encodeURIComponent(effectiveInboxId)}` : "https://send.api.mailtrap.io/api/send";
|
|
2222
3453
|
const res = await fetch(endpoint, {
|
|
2223
3454
|
method: "POST",
|
|
2224
3455
|
headers: {
|
|
2225
|
-
Authorization: `Bearer ${
|
|
3456
|
+
Authorization: `Bearer ${cleanToken}`,
|
|
3457
|
+
"Api-Token": cleanToken,
|
|
2226
3458
|
"Content-Type": "application/json"
|
|
2227
3459
|
},
|
|
2228
3460
|
body: JSON.stringify({
|
|
@@ -2239,7 +3471,7 @@ async function sendDynamicFormMail(params) {
|
|
|
2239
3471
|
}
|
|
2240
3472
|
return {
|
|
2241
3473
|
sent: true,
|
|
2242
|
-
driver:
|
|
3474
|
+
driver: effectiveInboxId ? "mailtrap-sandbox-api" : "mailtrap-sending-api",
|
|
2243
3475
|
detail: resBody
|
|
2244
3476
|
};
|
|
2245
3477
|
}
|
|
@@ -2367,10 +3599,10 @@ async function sendDynamicFormMail(params) {
|
|
|
2367
3599
|
}
|
|
2368
3600
|
const DEFAULT_SEED_SURVEYS = [
|
|
2369
3601
|
{
|
|
2370
|
-
title: "
|
|
3602
|
+
title: "Enterprise Product & Developer Experience Survey (3-Step)",
|
|
2371
3603
|
titleI18n: {
|
|
2372
|
-
|
|
2373
|
-
|
|
3604
|
+
en: "Enterprise Product & Developer Experience Survey",
|
|
3605
|
+
tr: "Kurumsal Ürün & Geliştirici Deneyimi Anketi"
|
|
2374
3606
|
},
|
|
2375
3607
|
slug: "showcase_dx_survey",
|
|
2376
3608
|
description: {
|
|
@@ -2706,10 +3938,10 @@ const DEFAULT_SEED_SURVEYS = [
|
|
|
2706
3938
|
}
|
|
2707
3939
|
},
|
|
2708
3940
|
{
|
|
2709
|
-
title: "
|
|
3941
|
+
title: "Quick Poll: What Should We Ship Next?",
|
|
2710
3942
|
titleI18n: {
|
|
2711
|
-
|
|
2712
|
-
|
|
3943
|
+
en: "Quick Poll: What Should We Ship Next?",
|
|
3944
|
+
tr: "Hızlı Oylama: Sıradaki Büyük Özellik Ne Olsun?"
|
|
2713
3945
|
},
|
|
2714
3946
|
slug: "showcase_roadmap_poll",
|
|
2715
3947
|
description: {
|
|
@@ -2780,10 +4012,10 @@ const DEFAULT_SEED_SURVEYS = [
|
|
|
2780
4012
|
}
|
|
2781
4013
|
},
|
|
2782
4014
|
{
|
|
2783
|
-
title: "
|
|
4015
|
+
title: "Visual Showcase & Readability Poll (Live Results)",
|
|
2784
4016
|
titleI18n: {
|
|
2785
|
-
|
|
2786
|
-
|
|
4017
|
+
en: "Visual Showcase & Readability Poll (Live Results)",
|
|
4018
|
+
tr: "Görsel Vitrin & Okunabilirlik Tercihi (Açık Sonuçlu)"
|
|
2787
4019
|
},
|
|
2788
4020
|
slug: "showcase_visual_theme_poll",
|
|
2789
4021
|
description: {
|
|
@@ -3284,7 +4516,7 @@ const DEFAULT_SEED_FORMS = [
|
|
|
3284
4516
|
title: "Enterprise Inquiry & Support Form",
|
|
3285
4517
|
slug: "showcase_contact_form",
|
|
3286
4518
|
to: "info@example.com",
|
|
3287
|
-
subject: "
|
|
4519
|
+
subject: "Enterprise Inquiry & Support Submission",
|
|
3288
4520
|
buttonLabel: {
|
|
3289
4521
|
tr: "Başvuruyu Gönder",
|
|
3290
4522
|
en: "Submit Inquiry"
|
|
@@ -3579,8 +4811,8 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3579
4811
|
} catch {
|
|
3580
4812
|
}
|
|
3581
4813
|
return [
|
|
3582
|
-
{ code: "
|
|
3583
|
-
{ code: "
|
|
4814
|
+
{ code: "en", name: "English (en)", isDefault: true },
|
|
4815
|
+
{ code: "tr", name: "Türkçe (tr)", isDefault: false }
|
|
3584
4816
|
];
|
|
3585
4817
|
},
|
|
3586
4818
|
async ensureSampleSubmissions(force = false) {
|
|
@@ -3614,6 +4846,22 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3614
4846
|
for (const seed of DEFAULT_SEED_FORMS) {
|
|
3615
4847
|
await strapi.db.query(FORM_UID).create({ data: seed });
|
|
3616
4848
|
}
|
|
4849
|
+
} else {
|
|
4850
|
+
try {
|
|
4851
|
+
const showcase = await strapi.db.query(FORM_UID).findOne({
|
|
4852
|
+
where: { slug: "showcase_contact_form" }
|
|
4853
|
+
});
|
|
4854
|
+
if (showcase && (showcase.subject === "Kurumsal İletişim & Destek Başvurusu" || showcase.title === "Kurumsal İletişim & Destek Formu")) {
|
|
4855
|
+
await strapi.db.query(FORM_UID).update({
|
|
4856
|
+
where: { id: showcase.id },
|
|
4857
|
+
data: {
|
|
4858
|
+
title: "Enterprise Inquiry & Support Form",
|
|
4859
|
+
subject: "Enterprise Inquiry & Support Submission"
|
|
4860
|
+
}
|
|
4861
|
+
});
|
|
4862
|
+
}
|
|
4863
|
+
} catch {
|
|
4864
|
+
}
|
|
3617
4865
|
}
|
|
3618
4866
|
await this.ensureSampleSubmissions(false);
|
|
3619
4867
|
},
|
|
@@ -3657,7 +4905,7 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3657
4905
|
return sanitizeFormForPublic(found);
|
|
3658
4906
|
},
|
|
3659
4907
|
async save(payload) {
|
|
3660
|
-
const cleanTitle = String(payload.title || "
|
|
4908
|
+
const cleanTitle = String(payload.title || "New Dynamic Form").trim();
|
|
3661
4909
|
const cleanSlug = String(
|
|
3662
4910
|
payload.slug || slugifyIdentifier$1(cleanTitle) || `form_${Date.now()}`
|
|
3663
4911
|
).trim();
|
|
@@ -3674,6 +4922,16 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3674
4922
|
if (!existing && cleanSlug) {
|
|
3675
4923
|
existing = await strapi.db.query(FORM_UID).findOne({ where: { slug: cleanSlug } });
|
|
3676
4924
|
}
|
|
4925
|
+
const mergedMailConfig = {
|
|
4926
|
+
...existing?.mailConfig || { driver: "env" },
|
|
4927
|
+
...payload.mailConfig || {}
|
|
4928
|
+
};
|
|
4929
|
+
if (mergedMailConfig.driver === "mailtrap" && mergedMailConfig.apiKey && !String(mergedMailConfig.inboxId || "").trim()) {
|
|
4930
|
+
const autoInbox = await discoverMailtrapSandboxInbox(mergedMailConfig.apiKey);
|
|
4931
|
+
if (autoInbox) {
|
|
4932
|
+
mergedMailConfig.inboxId = autoInbox;
|
|
4933
|
+
}
|
|
4934
|
+
}
|
|
3677
4935
|
const recordData = {
|
|
3678
4936
|
title: cleanTitle,
|
|
3679
4937
|
slug: cleanSlug,
|
|
@@ -3692,7 +4950,7 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3692
4950
|
useRecaptcha: payload.useRecaptcha !== void 0 ? Boolean(payload.useRecaptcha) : existing?.useRecaptcha !== void 0 ? Boolean(existing.useRecaptcha) : true,
|
|
3693
4951
|
recaptchaSiteKey: payload.recaptchaSiteKey !== void 0 ? String(payload.recaptchaSiteKey) : existing?.recaptchaSiteKey || "",
|
|
3694
4952
|
recaptchaSecretKey: payload.recaptchaSecretKey !== void 0 ? String(payload.recaptchaSecretKey) : existing?.recaptchaSecretKey || "",
|
|
3695
|
-
mailConfig:
|
|
4953
|
+
mailConfig: mergedMailConfig,
|
|
3696
4954
|
fields: payload.fields && typeof payload.fields === "object" ? payload.fields : existing?.fields || {},
|
|
3697
4955
|
form: Array.isArray(payload.form) ? payload.form : existing?.form || []
|
|
3698
4956
|
};
|
|
@@ -3761,8 +5019,8 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3761
5019
|
};
|
|
3762
5020
|
}
|
|
3763
5021
|
const body = rawBody && typeof rawBody === "object" ? rawBody : {};
|
|
3764
|
-
const rawLocale = String(body._locale || meta.locale || "
|
|
3765
|
-
const locale = rawLocale ? rawLocale.split(/[,;]/)[0].trim() : "
|
|
5022
|
+
const rawLocale = String(body._locale || meta.locale || "en").trim().toLowerCase();
|
|
5023
|
+
const locale = rawLocale ? rawLocale.split(/[,;]/)[0].trim() : "en";
|
|
3766
5024
|
const fieldsMap = form.fields && typeof form.fields === "object" ? form.fields : {};
|
|
3767
5025
|
const { errors } = validateFormSubmission(fieldsMap, body, locale);
|
|
3768
5026
|
const activeSecretKey = String(
|
|
@@ -3971,6 +5229,14 @@ const ciFormService = ({ strapi }) => ({
|
|
|
3971
5229
|
}
|
|
3972
5230
|
}
|
|
3973
5231
|
}
|
|
5232
|
+
if (imageObj) {
|
|
5233
|
+
try {
|
|
5234
|
+
imageObj = await enrichMediaAssetNode(strapi, imageObj, {
|
|
5235
|
+
defaultAutoMaxW: 960
|
|
5236
|
+
});
|
|
5237
|
+
} catch {
|
|
5238
|
+
}
|
|
5239
|
+
}
|
|
3974
5240
|
const pluralName = ct.info?.pluralName || "items";
|
|
3975
5241
|
const slugField = ["slug", "path", "url", "permalink"].find(
|
|
3976
5242
|
(k) => typeof entry[k] === "string" && entry[k].trim()
|
|
@@ -4059,7 +5325,7 @@ function isQuestionVisible(question, survey, answers) {
|
|
|
4059
5325
|
function lMsg(locale, tr, en) {
|
|
4060
5326
|
return String(locale || "").toLowerCase().startsWith("tr") ? tr : en;
|
|
4061
5327
|
}
|
|
4062
|
-
function validateSurveySubmission(survey, answers, otherTexts = {}, locale = "
|
|
5328
|
+
function validateSurveySubmission(survey, answers, otherTexts = {}, locale = "en") {
|
|
4063
5329
|
const errors = {};
|
|
4064
5330
|
const questions = Array.isArray(survey.questions) ? survey.questions : [];
|
|
4065
5331
|
for (const q of questions) {
|
|
@@ -4255,7 +5521,7 @@ function computeSurveyAnalytics(survey, rawResponses, filter = {}) {
|
|
|
4255
5521
|
const dailyCounts = {};
|
|
4256
5522
|
let lastSubmittedAt = null;
|
|
4257
5523
|
for (const r of responses) {
|
|
4258
|
-
const loc = String(r.locale || "
|
|
5524
|
+
const loc = String(r.locale || "en");
|
|
4259
5525
|
localeCounts[loc] = (localeCounts[loc] || 0) + 1;
|
|
4260
5526
|
const tsRaw = r.submittedAt || r.createdAt;
|
|
4261
5527
|
if (tsRaw) {
|
|
@@ -4317,7 +5583,7 @@ function computeSurveyAnalytics(survey, rawResponses, filter = {}) {
|
|
|
4317
5583
|
if (txt && otherSamples.length < 30) {
|
|
4318
5584
|
otherSamples.push({
|
|
4319
5585
|
text: txt,
|
|
4320
|
-
locale: r.locale || "
|
|
5586
|
+
locale: r.locale || "en",
|
|
4321
5587
|
submittedAt: r.submittedAt || r.createdAt || ""
|
|
4322
5588
|
});
|
|
4323
5589
|
}
|
|
@@ -4524,7 +5790,7 @@ function computeSurveyAnalytics(survey, rawResponses, filter = {}) {
|
|
|
4524
5790
|
textResponses.push({
|
|
4525
5791
|
id: r.id || r.documentId,
|
|
4526
5792
|
text: v.trim(),
|
|
4527
|
-
locale: r.locale || "
|
|
5793
|
+
locale: r.locale || "en",
|
|
4528
5794
|
submittedAt: r.submittedAt || r.createdAt || "",
|
|
4529
5795
|
npsValue: r.npsValue ?? null
|
|
4530
5796
|
});
|
|
@@ -4587,7 +5853,7 @@ function escapeCsvCell(val) {
|
|
|
4587
5853
|
}
|
|
4588
5854
|
return str;
|
|
4589
5855
|
}
|
|
4590
|
-
function exportSurveyResponsesToCsv(survey, rawResponses, locale = "
|
|
5856
|
+
function exportSurveyResponsesToCsv(survey, rawResponses, locale = "en") {
|
|
4591
5857
|
const activeQuestions = (survey.questions || []).filter((q) => q && q.type !== "statement");
|
|
4592
5858
|
const headers = [
|
|
4593
5859
|
"Response ID",
|
|
@@ -4970,6 +6236,12 @@ const ciSurveyService = ({ strapi }) => ({
|
|
|
4970
6236
|
settings: payload.settings ?? existing?.settings ?? {},
|
|
4971
6237
|
version: existing ? Number(existing.version || 1) + 1 : 1
|
|
4972
6238
|
};
|
|
6239
|
+
if (Array.isArray(recordData.questions) && recordData.questions.length > 0) {
|
|
6240
|
+
try {
|
|
6241
|
+
recordData.questions = await syncSurveyQuestionsMedia(strapi, recordData.questions);
|
|
6242
|
+
} catch {
|
|
6243
|
+
}
|
|
6244
|
+
}
|
|
4973
6245
|
if (existing) {
|
|
4974
6246
|
const updated = await strapi.db.query(SURVEY_UID).update({
|
|
4975
6247
|
where: { id: existing.id },
|
|
@@ -5003,8 +6275,8 @@ const ciSurveyService = ({ strapi }) => ({
|
|
|
5003
6275
|
};
|
|
5004
6276
|
}
|
|
5005
6277
|
const body = rawBody && typeof rawBody === "object" ? rawBody : {};
|
|
5006
|
-
const rawLocale = String(body._locale || meta.locale || "
|
|
5007
|
-
const locale = rawLocale ? rawLocale.split(/[,;]/)[0].trim() : "
|
|
6278
|
+
const rawLocale = String(body._locale || meta.locale || "en").trim().toLowerCase();
|
|
6279
|
+
const locale = rawLocale ? rawLocale.split(/[,;]/)[0].trim() : "en";
|
|
5008
6280
|
const isTr = locale.startsWith("tr");
|
|
5009
6281
|
if (body._hp && String(body._hp).trim() !== "") {
|
|
5010
6282
|
return {
|
|
@@ -5143,7 +6415,7 @@ const ciSurveyService = ({ strapi }) => ({
|
|
|
5143
6415
|
form: {
|
|
5144
6416
|
title: survey.title,
|
|
5145
6417
|
to: notifyEmails,
|
|
5146
|
-
subject:
|
|
6418
|
+
subject: `${isTr ? "[Anket Yanıtı]" : "[Survey Response]"} ${survey.title}`,
|
|
5147
6419
|
mailConfig: survey.mailConfig
|
|
5148
6420
|
},
|
|
5149
6421
|
data: {
|
|
@@ -5252,7 +6524,7 @@ const ciSurveyService = ({ strapi }) => ({
|
|
|
5252
6524
|
const csv = exportSurveyResponsesToCsv(
|
|
5253
6525
|
survey,
|
|
5254
6526
|
responses,
|
|
5255
|
-
options2.locale || "
|
|
6527
|
+
options2.locale || "en"
|
|
5256
6528
|
);
|
|
5257
6529
|
return {
|
|
5258
6530
|
filename: `${survey.slug}-responses.csv`,
|
|
@@ -5261,11 +6533,615 @@ const ciSurveyService = ({ strapi }) => ({
|
|
|
5261
6533
|
};
|
|
5262
6534
|
}
|
|
5263
6535
|
});
|
|
6536
|
+
const PALETTE_UID = "plugin::content-input.ci-color-palette";
|
|
6537
|
+
function clamp(n, min, max) {
|
|
6538
|
+
return Math.max(min, Math.min(max, n));
|
|
6539
|
+
}
|
|
6540
|
+
function parseColorToRgba(rawInput, fallback = { r: 79, g: 70, b: 229, a: 1 }) {
|
|
6541
|
+
const str = String(rawInput || "").trim();
|
|
6542
|
+
if (!str) return fallback;
|
|
6543
|
+
const varMatch = str.match(/^var\([^,]+,\s*(.+)\)$/);
|
|
6544
|
+
const target = varMatch ? varMatch[1].trim() : str;
|
|
6545
|
+
const hexMatch = target.match(/^#([0-9a-fA-F]{3,8})$/);
|
|
6546
|
+
if (hexMatch) {
|
|
6547
|
+
const h = hexMatch[1];
|
|
6548
|
+
if (h.length === 3 || h.length === 4) {
|
|
6549
|
+
const r = parseInt(h[0] + h[0], 16);
|
|
6550
|
+
const g = parseInt(h[1] + h[1], 16);
|
|
6551
|
+
const b = parseInt(h[2] + h[2], 16);
|
|
6552
|
+
const a = h.length === 4 ? Number((parseInt(h[3] + h[3], 16) / 255).toFixed(2)) : 1;
|
|
6553
|
+
return { r, g, b, a };
|
|
6554
|
+
}
|
|
6555
|
+
if (h.length === 6 || h.length === 8) {
|
|
6556
|
+
const r = parseInt(h.slice(0, 2), 16);
|
|
6557
|
+
const g = parseInt(h.slice(2, 4), 16);
|
|
6558
|
+
const b = parseInt(h.slice(4, 6), 16);
|
|
6559
|
+
const a = h.length === 8 ? Number((parseInt(h.slice(6, 8), 16) / 255).toFixed(2)) : 1;
|
|
6560
|
+
return { r, g, b, a };
|
|
6561
|
+
}
|
|
6562
|
+
}
|
|
6563
|
+
const rgbMatch = target.match(/^rgba?\(\s*([\d.]+)\s*[,\s]\s*([\d.]+)\s*[,\s]\s*([\d.]+)(?:\s*[,/]\s*([\d.%]+))?\s*\)$/i);
|
|
6564
|
+
if (rgbMatch) {
|
|
6565
|
+
const r = clamp(Math.round(Number(rgbMatch[1])), 0, 255);
|
|
6566
|
+
const g = clamp(Math.round(Number(rgbMatch[2])), 0, 255);
|
|
6567
|
+
const b = clamp(Math.round(Number(rgbMatch[3])), 0, 255);
|
|
6568
|
+
let a = 1;
|
|
6569
|
+
if (rgbMatch[4] !== void 0) {
|
|
6570
|
+
const rawA = rgbMatch[4].trim();
|
|
6571
|
+
a = rawA.endsWith("%") ? clamp(Number(rawA.slice(0, -1)) / 100, 0, 1) : clamp(Number(rawA), 0, 1);
|
|
6572
|
+
a = Number(a.toFixed(2));
|
|
6573
|
+
}
|
|
6574
|
+
return { r, g, b, a };
|
|
6575
|
+
}
|
|
6576
|
+
return fallback;
|
|
6577
|
+
}
|
|
6578
|
+
function rgbaToHex({ r, g, b, a }) {
|
|
6579
|
+
const to2 = (n) => clamp(Math.round(n), 0, 255).toString(16).padStart(2, "0");
|
|
6580
|
+
if (a < 1) {
|
|
6581
|
+
return `#${to2(r)}${to2(g)}${to2(b)}${to2(Math.round(a * 255))}`;
|
|
6582
|
+
}
|
|
6583
|
+
return `#${to2(r)}${to2(g)}${to2(b)}`;
|
|
6584
|
+
}
|
|
6585
|
+
function rgbaToCssString({ r, g, b, a }) {
|
|
6586
|
+
const cr = clamp(Math.round(r), 0, 255);
|
|
6587
|
+
const cg = clamp(Math.round(g), 0, 255);
|
|
6588
|
+
const cb = clamp(Math.round(b), 0, 255);
|
|
6589
|
+
const ca = clamp(Number(a.toFixed(2)), 0, 1);
|
|
6590
|
+
return ca < 1 ? `rgba(${cr}, ${cg}, ${cb}, ${ca})` : `rgb(${cr}, ${cg}, ${cb})`;
|
|
6591
|
+
}
|
|
6592
|
+
function buildTokenEntry(rawVal, labels, overrides) {
|
|
6593
|
+
const parsed = parseColorToRgba(rawVal);
|
|
6594
|
+
const hex = rgbaToHex(parsed);
|
|
6595
|
+
const rgb = rgbaToCssString(parsed);
|
|
6596
|
+
const cleanTrimmed = String(rawVal || "").trim();
|
|
6597
|
+
const value = cleanTrimmed.toLowerCase().startsWith("rgb") ? rgb : hex;
|
|
6598
|
+
const srgb = [parsed.r, parsed.g, parsed.b].map((v) => {
|
|
6599
|
+
const c = v / 255;
|
|
6600
|
+
return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
6601
|
+
});
|
|
6602
|
+
const lum = 0.2126 * srgb[0] + 0.7152 * srgb[1] + 0.0722 * srgb[2];
|
|
6603
|
+
const autoContrast = lum > 0.44 ? "#0f172a" : "#ffffff";
|
|
6604
|
+
const autoSoft = `rgba(${parsed.r}, ${parsed.g}, ${parsed.b}, 0.14)`;
|
|
6605
|
+
return {
|
|
6606
|
+
value,
|
|
6607
|
+
hex,
|
|
6608
|
+
rgb,
|
|
6609
|
+
soft: overrides?.soft || autoSoft,
|
|
6610
|
+
contrast: overrides?.contrast || autoContrast,
|
|
6611
|
+
...labels ? { labels } : {}
|
|
6612
|
+
};
|
|
6613
|
+
}
|
|
6614
|
+
const SEMANTIC_TOKEN_META = [
|
|
6615
|
+
{ key: "primary", tr: "Birincil (Primary)", en: "Primary" },
|
|
6616
|
+
{ key: "secondary", tr: "İkincil (Secondary)", en: "Secondary" },
|
|
6617
|
+
{ key: "accent", tr: "Vurgu (Accent)", en: "Accent" },
|
|
6618
|
+
{ key: "success", tr: "Başarı (Success)", en: "Success" },
|
|
6619
|
+
{ key: "warning", tr: "Uyarı (Warning)", en: "Warning" },
|
|
6620
|
+
{ key: "error", tr: "Hata / Tehlike (Error)", en: "Error" },
|
|
6621
|
+
{ key: "info", tr: "Bilgi (Info)", en: "Info" },
|
|
6622
|
+
{ key: "surface", tr: "Kart / Yüzey (Surface)", en: "Surface" },
|
|
6623
|
+
{ key: "surfaceAlt", tr: "Alternatif Yüzey", en: "Surface Alt" },
|
|
6624
|
+
{ key: "background", tr: "Sayfa Arka Planı", en: "Background" },
|
|
6625
|
+
{ key: "textPrimary", tr: "Ana Metin Rengi", en: "Primary Text" },
|
|
6626
|
+
{ key: "textSecondary", tr: "İkincil Metin Rengi", en: "Secondary Text" },
|
|
6627
|
+
{ key: "border", tr: "Kenarlık (Border)", en: "Border" }
|
|
6628
|
+
];
|
|
6629
|
+
const DEFAULT_PALETTE_SEEDS = [
|
|
6630
|
+
{
|
|
6631
|
+
name: "Enterprise Indigo (Default)",
|
|
6632
|
+
slug: "enterprise-indigo",
|
|
6633
|
+
description: "Balanced Indigo, Sky Blue, and Dark Slate palette for modern SaaS & enterprise interfaces",
|
|
6634
|
+
isActive: true,
|
|
6635
|
+
rawSemantic: {
|
|
6636
|
+
primary: "#4f46e5",
|
|
6637
|
+
secondary: "#0ea5e9",
|
|
6638
|
+
accent: "#8b5cf6",
|
|
6639
|
+
success: "#10b981",
|
|
6640
|
+
warning: "#f59e0b",
|
|
6641
|
+
error: "#ef4444",
|
|
6642
|
+
info: "#3b82f6",
|
|
6643
|
+
surface: "#ffffff",
|
|
6644
|
+
surfaceAlt: "#f8fafc",
|
|
6645
|
+
background: "#f1f5f9",
|
|
6646
|
+
textPrimary: "#0f172a",
|
|
6647
|
+
textSecondary: "#475569",
|
|
6648
|
+
border: "#e2e8f0"
|
|
6649
|
+
},
|
|
6650
|
+
rawCustom: [
|
|
6651
|
+
{ key: "brandGold", value: "#d97706", labels: { tr: "Kurumsal Altın", en: "Brand Gold" } },
|
|
6652
|
+
{ key: "heroCyan", value: "rgb(6, 182, 212)", labels: { tr: "Vitrin Turkuaz (RGB)", en: "Hero Cyan (RGB)" } },
|
|
6653
|
+
{ key: "glassDark", value: "rgba(15, 23, 42, 0.76)", labels: { tr: "Koyu Cam Efekt (RGBA)", en: "Dark Glass Scrim (RGBA)" } },
|
|
6654
|
+
{ key: "coralHighlight", value: "#f43f5e", labels: { tr: "Mercan Vurgu", en: "Coral Highlight" } }
|
|
6655
|
+
]
|
|
6656
|
+
},
|
|
6657
|
+
{
|
|
6658
|
+
name: "Emerald Fintech & Sustainability",
|
|
6659
|
+
slug: "emerald-fintech",
|
|
6660
|
+
description: "Emerald Green & Ocean Navy palette crafted for fintech, energy, and sustainability platforms",
|
|
6661
|
+
isActive: false,
|
|
6662
|
+
rawSemantic: {
|
|
6663
|
+
primary: "#059669",
|
|
6664
|
+
secondary: "#0f766e",
|
|
6665
|
+
accent: "#0284c7",
|
|
6666
|
+
success: "#16a34a",
|
|
6667
|
+
warning: "#d97706",
|
|
6668
|
+
error: "#dc2626",
|
|
6669
|
+
info: "#0ea5e9",
|
|
6670
|
+
surface: "#ffffff",
|
|
6671
|
+
surfaceAlt: "#f0fdf4",
|
|
6672
|
+
background: "#f8fafc",
|
|
6673
|
+
textPrimary: "#064e3b",
|
|
6674
|
+
textSecondary: "#334155",
|
|
6675
|
+
border: "#d1fae5"
|
|
6676
|
+
},
|
|
6677
|
+
rawCustom: [
|
|
6678
|
+
{ key: "brandGold", value: "#ca8a04", labels: { tr: "Kurumsal Altın", en: "Brand Gold" } },
|
|
6679
|
+
{ key: "heroCyan", value: "rgb(20, 184, 166)", labels: { tr: "Mint Yeşil (RGB)", en: "Mint Teal (RGB)" } },
|
|
6680
|
+
{ key: "glassDark", value: "rgba(6, 78, 59, 0.78)", labels: { tr: "Zümrüt Cam (RGBA)", en: "Emerald Glass (RGBA)" } },
|
|
6681
|
+
{ key: "coralHighlight", value: "#ea580c", labels: { tr: "Sıcak Turuncu", en: "Warm Terracotta" } }
|
|
6682
|
+
]
|
|
6683
|
+
},
|
|
6684
|
+
{
|
|
6685
|
+
name: "Royal Amber & Executive Navy",
|
|
6686
|
+
slug: "royal-amber",
|
|
6687
|
+
description: "Executive Navy & Royal Amber Gold palette for corporate holdings, legal, real estate, and luxury brands",
|
|
6688
|
+
isActive: false,
|
|
6689
|
+
rawSemantic: {
|
|
6690
|
+
primary: "#1e3a8a",
|
|
6691
|
+
secondary: "#d97706",
|
|
6692
|
+
accent: "#b45309",
|
|
6693
|
+
success: "#15803d",
|
|
6694
|
+
warning: "#eab308",
|
|
6695
|
+
error: "#b91c1c",
|
|
6696
|
+
info: "#1d4ed8",
|
|
6697
|
+
surface: "#ffffff",
|
|
6698
|
+
surfaceAlt: "#fffbeb",
|
|
6699
|
+
background: "#f8fafc",
|
|
6700
|
+
textPrimary: "#0f172a",
|
|
6701
|
+
textSecondary: "#475569",
|
|
6702
|
+
border: "#e2e8f0"
|
|
6703
|
+
},
|
|
6704
|
+
rawCustom: [
|
|
6705
|
+
{ key: "brandGold", value: "#f59e0b", labels: { tr: "Kraliyet Altını", en: "Royal Gold" } },
|
|
6706
|
+
{ key: "heroCyan", value: "rgb(59, 130, 246)", labels: { tr: "Kraliyet Mavisi (RGB)", en: "Royal Blue (RGB)" } },
|
|
6707
|
+
{ key: "glassDark", value: "rgba(23, 37, 84, 0.82)", labels: { tr: "Lacivert Cam (RGBA)", en: "Navy Glass (RGBA)" } },
|
|
6708
|
+
{ key: "coralHighlight", value: "#e11d48", labels: { tr: "Yakut Vurgu", en: "Ruby Highlight" } }
|
|
6709
|
+
]
|
|
6710
|
+
},
|
|
6711
|
+
{
|
|
6712
|
+
name: "Crimson Editorial & Media",
|
|
6713
|
+
slug: "crimson-editorial",
|
|
6714
|
+
description: "High-energy Crimson & Violet palette for editorial media, e-commerce campaigns, and digital agencies",
|
|
6715
|
+
isActive: false,
|
|
6716
|
+
rawSemantic: {
|
|
6717
|
+
primary: "#e11d48",
|
|
6718
|
+
secondary: "#7c3aed",
|
|
6719
|
+
accent: "#f97316",
|
|
6720
|
+
success: "#10b981",
|
|
6721
|
+
warning: "#f59e0b",
|
|
6722
|
+
error: "#dc2626",
|
|
6723
|
+
info: "#6366f1",
|
|
6724
|
+
surface: "#ffffff",
|
|
6725
|
+
surfaceAlt: "#fff1f2",
|
|
6726
|
+
background: "#fafafa",
|
|
6727
|
+
textPrimary: "#18181b",
|
|
6728
|
+
textSecondary: "#52525b",
|
|
6729
|
+
border: "#e4e4e7"
|
|
6730
|
+
},
|
|
6731
|
+
rawCustom: [
|
|
6732
|
+
{ key: "brandGold", value: "#f97316", labels: { tr: "Kampanya Turuncusu", en: "Campaign Orange" } },
|
|
6733
|
+
{ key: "heroCyan", value: "rgb(168, 85, 247)", labels: { tr: "Neon Mor (RGB)", en: "Neon Purple (RGB)" } },
|
|
6734
|
+
{ key: "glassDark", value: "rgba(24, 24, 27, 0.80)", labels: { tr: "Antrasit Cam (RGBA)", en: "Charcoal Glass (RGBA)" } },
|
|
6735
|
+
{ key: "coralHighlight", value: "#f43f5e", labels: { tr: "Mercan Vurgu", en: "Coral Highlight" } }
|
|
6736
|
+
]
|
|
6737
|
+
}
|
|
6738
|
+
];
|
|
6739
|
+
function normalizePalettePayload(raw) {
|
|
6740
|
+
const semanticIn = raw?.semanticTokens && typeof raw.semanticTokens === "object" ? raw.semanticTokens : {};
|
|
6741
|
+
const semanticTokens = {};
|
|
6742
|
+
for (const meta of SEMANTIC_TOKEN_META) {
|
|
6743
|
+
const incoming = semanticIn[meta.key];
|
|
6744
|
+
const rawColor = typeof incoming === "string" ? incoming : incoming?.value || incoming?.hex || incoming?.rgb || "#4f46e5";
|
|
6745
|
+
semanticTokens[meta.key] = buildTokenEntry(
|
|
6746
|
+
rawColor,
|
|
6747
|
+
incoming?.labels || { tr: meta.tr, en: meta.en },
|
|
6748
|
+
{
|
|
6749
|
+
soft: incoming?.soft,
|
|
6750
|
+
contrast: incoming?.contrast
|
|
6751
|
+
}
|
|
6752
|
+
);
|
|
6753
|
+
}
|
|
6754
|
+
const customIn = Array.isArray(raw?.customTokens) ? raw.customTokens : [];
|
|
6755
|
+
const customTokens = customIn.filter((c) => c && typeof c.key === "string" && c.key.trim()).map((c) => {
|
|
6756
|
+
const cleanKey = String(c.key).trim().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
6757
|
+
const base = buildTokenEntry(
|
|
6758
|
+
c.value || c.hex || c.rgb || "#4f46e5",
|
|
6759
|
+
c.labels && typeof c.labels === "object" ? c.labels : { tr: cleanKey, en: cleanKey },
|
|
6760
|
+
{
|
|
6761
|
+
soft: c.soft,
|
|
6762
|
+
contrast: c.contrast
|
|
6763
|
+
}
|
|
6764
|
+
);
|
|
6765
|
+
return {
|
|
6766
|
+
key: cleanKey,
|
|
6767
|
+
...base,
|
|
6768
|
+
labels: c.labels && typeof c.labels === "object" ? c.labels : { tr: cleanKey, en: cleanKey }
|
|
6769
|
+
};
|
|
6770
|
+
});
|
|
6771
|
+
return {
|
|
6772
|
+
name: String(raw?.name || "Custom Theme Palette").trim(),
|
|
6773
|
+
slug: String(raw?.slug || raw?.name || "custom-palette").toLowerCase().replace(/[^a-z0-9-_]+/g, "-").replace(/^-+|-+$/g, "") || `palette-${Date.now()}`,
|
|
6774
|
+
description: String(raw?.description || "").trim(),
|
|
6775
|
+
isActive: Boolean(raw?.isActive),
|
|
6776
|
+
semanticTokens,
|
|
6777
|
+
customTokens
|
|
6778
|
+
};
|
|
6779
|
+
}
|
|
6780
|
+
function buildCssVariablesMap(palette) {
|
|
6781
|
+
const vars = {};
|
|
6782
|
+
if (!palette) return vars;
|
|
6783
|
+
const sem = palette.semanticTokens || {};
|
|
6784
|
+
for (const [key, entry] of Object.entries(sem)) {
|
|
6785
|
+
if (!entry) continue;
|
|
6786
|
+
const val = entry.value || entry.hex || "#4f46e5";
|
|
6787
|
+
vars[`--ci-color-${key}`] = val;
|
|
6788
|
+
if (entry.soft) vars[`--ci-color-${key}-soft`] = entry.soft;
|
|
6789
|
+
if (entry.contrast) vars[`--ci-color-${key}-contrast`] = entry.contrast;
|
|
6790
|
+
if (entry.hex) vars[`--ci-color-${key}-hex`] = entry.hex;
|
|
6791
|
+
if (entry.rgb) vars[`--ci-color-${key}-rgb`] = entry.rgb;
|
|
6792
|
+
}
|
|
6793
|
+
const cust = Array.isArray(palette.customTokens) ? palette.customTokens : [];
|
|
6794
|
+
for (const item of cust) {
|
|
6795
|
+
if (!item?.key) continue;
|
|
6796
|
+
const val = item.value || item.hex || "#4f46e5";
|
|
6797
|
+
vars[`--ci-color-${item.key}`] = val;
|
|
6798
|
+
if (item.soft) vars[`--ci-color-${item.key}-soft`] = item.soft;
|
|
6799
|
+
if (item.contrast) vars[`--ci-color-${item.key}-contrast`] = item.contrast;
|
|
6800
|
+
}
|
|
6801
|
+
return vars;
|
|
6802
|
+
}
|
|
6803
|
+
const ciColorService = ({ strapi }) => ({
|
|
6804
|
+
async ensureSeeded() {
|
|
6805
|
+
const existing = await strapi.db.query(PALETTE_UID).findMany({ limit: 50 });
|
|
6806
|
+
if (Array.isArray(existing) && existing.length > 0) {
|
|
6807
|
+
const hasActive = existing.some((p) => p.isActive);
|
|
6808
|
+
if (!hasActive && existing[0]?.id) {
|
|
6809
|
+
await strapi.db.query(PALETTE_UID).update({
|
|
6810
|
+
where: { id: existing[0].id },
|
|
6811
|
+
data: { isActive: true }
|
|
6812
|
+
});
|
|
6813
|
+
}
|
|
6814
|
+
return;
|
|
6815
|
+
}
|
|
6816
|
+
for (const seed of DEFAULT_PALETTE_SEEDS) {
|
|
6817
|
+
const semanticTokens = {};
|
|
6818
|
+
for (const meta of SEMANTIC_TOKEN_META) {
|
|
6819
|
+
const rawHex = seed.rawSemantic[meta.key] || "#4f46e5";
|
|
6820
|
+
semanticTokens[meta.key] = buildTokenEntry(rawHex, { tr: meta.tr, en: meta.en });
|
|
6821
|
+
}
|
|
6822
|
+
const customTokens = seed.rawCustom.map((c) => ({
|
|
6823
|
+
key: c.key,
|
|
6824
|
+
...buildTokenEntry(c.value, c.labels),
|
|
6825
|
+
labels: c.labels
|
|
6826
|
+
}));
|
|
6827
|
+
await strapi.db.query(PALETTE_UID).create({
|
|
6828
|
+
data: {
|
|
6829
|
+
name: seed.name,
|
|
6830
|
+
slug: seed.slug,
|
|
6831
|
+
description: seed.description,
|
|
6832
|
+
isActive: seed.isActive,
|
|
6833
|
+
semanticTokens,
|
|
6834
|
+
customTokens
|
|
6835
|
+
}
|
|
6836
|
+
});
|
|
6837
|
+
}
|
|
6838
|
+
},
|
|
6839
|
+
async findAll() {
|
|
6840
|
+
await this.ensureSeeded();
|
|
6841
|
+
const palettes = await strapi.db.query(PALETTE_UID).findMany({
|
|
6842
|
+
orderBy: { id: "asc" }
|
|
6843
|
+
});
|
|
6844
|
+
const active = palettes.find((p) => p.isActive) || palettes[0] || null;
|
|
6845
|
+
return {
|
|
6846
|
+
data: palettes,
|
|
6847
|
+
active,
|
|
6848
|
+
cssVariables: buildCssVariablesMap(active)
|
|
6849
|
+
};
|
|
6850
|
+
},
|
|
6851
|
+
async findActivePublic(slugOverride) {
|
|
6852
|
+
await this.ensureSeeded();
|
|
6853
|
+
const allPalettes = await strapi.db.query(PALETTE_UID).findMany({
|
|
6854
|
+
orderBy: { id: "asc" }
|
|
6855
|
+
});
|
|
6856
|
+
let palette = null;
|
|
6857
|
+
if (slugOverride) {
|
|
6858
|
+
palette = allPalettes.find((p) => p.slug === slugOverride) || null;
|
|
6859
|
+
}
|
|
6860
|
+
if (!palette) {
|
|
6861
|
+
palette = allPalettes.find((p) => p.isActive) || allPalettes[0] || null;
|
|
6862
|
+
}
|
|
6863
|
+
return {
|
|
6864
|
+
data: palette,
|
|
6865
|
+
palette,
|
|
6866
|
+
palettes: allPalettes.map((p) => ({
|
|
6867
|
+
name: p.name,
|
|
6868
|
+
slug: p.slug,
|
|
6869
|
+
isActive: Boolean(p.isActive),
|
|
6870
|
+
primary: p.semanticTokens?.primary?.value || p.semanticTokens?.primary?.hex || "#4f46e5",
|
|
6871
|
+
secondary: p.semanticTokens?.secondary?.value || p.semanticTokens?.secondary?.hex || "#0ea5e9",
|
|
6872
|
+
accent: p.semanticTokens?.accent?.value || p.semanticTokens?.accent?.hex || "#f59e0b"
|
|
6873
|
+
})),
|
|
6874
|
+
cssVariables: buildCssVariablesMap(palette)
|
|
6875
|
+
};
|
|
6876
|
+
},
|
|
6877
|
+
async save(payload) {
|
|
6878
|
+
await this.ensureSeeded();
|
|
6879
|
+
const normalized = normalizePalettePayload(payload);
|
|
6880
|
+
let existing = null;
|
|
6881
|
+
if (payload?.id) {
|
|
6882
|
+
existing = await strapi.db.query(PALETTE_UID).findOne({ where: { id: Number(payload.id) } });
|
|
6883
|
+
}
|
|
6884
|
+
if (!existing && payload?.documentId) {
|
|
6885
|
+
existing = await strapi.db.query(PALETTE_UID).findOne({ where: { documentId: payload.documentId } });
|
|
6886
|
+
}
|
|
6887
|
+
if (!existing && normalized.slug) {
|
|
6888
|
+
existing = await strapi.db.query(PALETTE_UID).findOne({ where: { slug: normalized.slug } });
|
|
6889
|
+
}
|
|
6890
|
+
if (normalized.isActive) {
|
|
6891
|
+
await strapi.db.query(PALETTE_UID).updateMany({
|
|
6892
|
+
where: { isActive: true },
|
|
6893
|
+
data: { isActive: false }
|
|
6894
|
+
});
|
|
6895
|
+
}
|
|
6896
|
+
let saved;
|
|
6897
|
+
if (existing) {
|
|
6898
|
+
saved = await strapi.db.query(PALETTE_UID).update({
|
|
6899
|
+
where: { id: existing.id },
|
|
6900
|
+
data: {
|
|
6901
|
+
...normalized,
|
|
6902
|
+
isActive: normalized.isActive || existing.isActive
|
|
6903
|
+
}
|
|
6904
|
+
});
|
|
6905
|
+
} else {
|
|
6906
|
+
saved = await strapi.db.query(PALETTE_UID).create({
|
|
6907
|
+
data: normalized
|
|
6908
|
+
});
|
|
6909
|
+
}
|
|
6910
|
+
return this.findAll().then((res) => ({
|
|
6911
|
+
...res,
|
|
6912
|
+
saved
|
|
6913
|
+
}));
|
|
6914
|
+
},
|
|
6915
|
+
async activate(idOrSlug) {
|
|
6916
|
+
await this.ensureSeeded();
|
|
6917
|
+
const str = String(idOrSlug).trim();
|
|
6918
|
+
let target = null;
|
|
6919
|
+
if (/^\d+$/.test(str)) {
|
|
6920
|
+
target = await strapi.db.query(PALETTE_UID).findOne({ where: { id: Number(str) } });
|
|
6921
|
+
}
|
|
6922
|
+
if (!target) {
|
|
6923
|
+
target = await strapi.db.query(PALETTE_UID).findOne({
|
|
6924
|
+
where: { $or: [{ slug: str }, { documentId: str }] }
|
|
6925
|
+
});
|
|
6926
|
+
}
|
|
6927
|
+
if (!target) return null;
|
|
6928
|
+
await strapi.db.query(PALETTE_UID).updateMany({
|
|
6929
|
+
where: { isActive: true },
|
|
6930
|
+
data: { isActive: false }
|
|
6931
|
+
});
|
|
6932
|
+
await strapi.db.query(PALETTE_UID).update({
|
|
6933
|
+
where: { id: target.id },
|
|
6934
|
+
data: { isActive: true }
|
|
6935
|
+
});
|
|
6936
|
+
return this.findAll();
|
|
6937
|
+
},
|
|
6938
|
+
async upsertQuickCustomToken(input) {
|
|
6939
|
+
await this.ensureSeeded();
|
|
6940
|
+
const { active } = await this.findActivePublic().then((r) => ({ active: r.data }));
|
|
6941
|
+
if (!active) return null;
|
|
6942
|
+
const cleanKey = String(input.key || input.label || "customColor").trim().replace(/[^a-zA-Z0-9_-]/g, "") || `color_${Date.now()}`;
|
|
6943
|
+
const labelStr = String(input.label || cleanKey).trim();
|
|
6944
|
+
const labels = input.labels && typeof input.labels === "object" ? input.labels : { tr: labelStr, en: labelStr };
|
|
6945
|
+
const tokenEntry = {
|
|
6946
|
+
key: cleanKey,
|
|
6947
|
+
...buildTokenEntry(input.value, labels),
|
|
6948
|
+
labels
|
|
6949
|
+
};
|
|
6950
|
+
const prevCustom = Array.isArray(active.customTokens) ? [...active.customTokens] : [];
|
|
6951
|
+
const idx = prevCustom.findIndex((t) => t.key === cleanKey);
|
|
6952
|
+
if (idx >= 0) {
|
|
6953
|
+
prevCustom[idx] = tokenEntry;
|
|
6954
|
+
} else {
|
|
6955
|
+
prevCustom.push(tokenEntry);
|
|
6956
|
+
}
|
|
6957
|
+
await strapi.db.query(PALETTE_UID).update({
|
|
6958
|
+
where: { id: active.id },
|
|
6959
|
+
data: { customTokens: prevCustom }
|
|
6960
|
+
});
|
|
6961
|
+
return {
|
|
6962
|
+
...await this.findAll(),
|
|
6963
|
+
addedToken: tokenEntry
|
|
6964
|
+
};
|
|
6965
|
+
},
|
|
6966
|
+
async remove(idOrSlug) {
|
|
6967
|
+
const str = String(idOrSlug).trim();
|
|
6968
|
+
const all = await strapi.db.query(PALETTE_UID).findMany();
|
|
6969
|
+
if (all.length <= 1) {
|
|
6970
|
+
throw new Error("Cannot delete the last remaining color palette");
|
|
6971
|
+
}
|
|
6972
|
+
const target = all.find(
|
|
6973
|
+
(p) => String(p.id) === str || p.slug === str || p.documentId === str
|
|
6974
|
+
);
|
|
6975
|
+
if (!target) return this.findAll();
|
|
6976
|
+
await strapi.db.query(PALETTE_UID).delete({ where: { id: target.id } });
|
|
6977
|
+
if (target.isActive) {
|
|
6978
|
+
const remaining = await strapi.db.query(PALETTE_UID).findMany({ limit: 1 });
|
|
6979
|
+
if (remaining[0]) {
|
|
6980
|
+
await strapi.db.query(PALETTE_UID).update({
|
|
6981
|
+
where: { id: remaining[0].id },
|
|
6982
|
+
data: { isActive: true }
|
|
6983
|
+
});
|
|
6984
|
+
}
|
|
6985
|
+
}
|
|
6986
|
+
return this.findAll();
|
|
6987
|
+
},
|
|
6988
|
+
/**
|
|
6989
|
+
* Safe public collection query for Data Table (`sourceMode: 'strapi_collection'`)
|
|
6990
|
+
*/
|
|
6991
|
+
async queryCollectionForDataTable(params) {
|
|
6992
|
+
const uid = String(params.uid || "").trim();
|
|
6993
|
+
if (!uid.startsWith("api::")) {
|
|
6994
|
+
return { columns: [], rows: [] };
|
|
6995
|
+
}
|
|
6996
|
+
const ct = strapi.contentTypes[uid];
|
|
6997
|
+
if (!ct) {
|
|
6998
|
+
return { columns: [], rows: [] };
|
|
6999
|
+
}
|
|
7000
|
+
const attrs = ct.attributes || {};
|
|
7001
|
+
const forbiddenTypes = /* @__PURE__ */ new Set(["password", "dynamiczone", "component", "relation"]);
|
|
7002
|
+
const allowedFields = [
|
|
7003
|
+
{ key: "documentId", type: "text" }
|
|
7004
|
+
];
|
|
7005
|
+
for (const [fieldName, attr] of Object.entries(attrs)) {
|
|
7006
|
+
if (!attr || attr.private) continue;
|
|
7007
|
+
if (/password|secret|token|hash/i.test(fieldName)) continue;
|
|
7008
|
+
if (attr.customField === "plugin::content-input.content-input") continue;
|
|
7009
|
+
if (forbiddenTypes.has(attr.type)) continue;
|
|
7010
|
+
allowedFields.push({ key: fieldName, type: attr.type || "string" });
|
|
7011
|
+
}
|
|
7012
|
+
for (const sysKey of ["createdAt", "updatedAt", "publishedAt"]) {
|
|
7013
|
+
if (!allowedFields.some((f) => f.key === sysKey)) {
|
|
7014
|
+
allowedFields.push({ key: sysKey, type: "datetime" });
|
|
7015
|
+
}
|
|
7016
|
+
}
|
|
7017
|
+
if (!allowedFields.some((f) => f.key === "collectionLabel")) {
|
|
7018
|
+
allowedFields.push({ key: "collectionLabel", type: "enumeration" });
|
|
7019
|
+
}
|
|
7020
|
+
if (attrs.slug && !allowedFields.some((f) => f.key === "url")) {
|
|
7021
|
+
allowedFields.push({ key: "url", type: "uid" });
|
|
7022
|
+
}
|
|
7023
|
+
const limit = clamp(Number(params.limit) || 25, 1, 100);
|
|
7024
|
+
let entries = [];
|
|
7025
|
+
try {
|
|
7026
|
+
const docService = strapi.documents?.(uid);
|
|
7027
|
+
if (docService) {
|
|
7028
|
+
entries = await docService.findMany({
|
|
7029
|
+
status: "published",
|
|
7030
|
+
limit,
|
|
7031
|
+
sort: params.sort || "createdAt:desc",
|
|
7032
|
+
populate: "*"
|
|
7033
|
+
});
|
|
7034
|
+
if (!entries.length) {
|
|
7035
|
+
entries = await docService.findMany({
|
|
7036
|
+
limit,
|
|
7037
|
+
sort: params.sort || "createdAt:desc",
|
|
7038
|
+
populate: "*"
|
|
7039
|
+
});
|
|
7040
|
+
}
|
|
7041
|
+
} else {
|
|
7042
|
+
entries = await strapi.db.query(uid).findMany({ limit, populate: true });
|
|
7043
|
+
}
|
|
7044
|
+
} catch {
|
|
7045
|
+
entries = [];
|
|
7046
|
+
}
|
|
7047
|
+
const collectionLabelText = ct.info?.displayName || uid;
|
|
7048
|
+
const fileCache = /* @__PURE__ */ new Map();
|
|
7049
|
+
const sanitizedRows = await Promise.all(
|
|
7050
|
+
(entries || []).map(async (entry) => {
|
|
7051
|
+
const row = {};
|
|
7052
|
+
for (const f of allowedFields) {
|
|
7053
|
+
if (f.key === "collectionLabel" && entry.collectionLabel === void 0) {
|
|
7054
|
+
row.collectionLabel = collectionLabelText;
|
|
7055
|
+
continue;
|
|
7056
|
+
}
|
|
7057
|
+
if (f.key === "url" && entry.url === void 0) {
|
|
7058
|
+
const slugStr = entry.slug ? String(entry.slug).trim() : "";
|
|
7059
|
+
row.url = slugStr ? slugStr === "home" ? "/" : `/${slugStr.replace(/^\/+/, "")}` : "";
|
|
7060
|
+
continue;
|
|
7061
|
+
}
|
|
7062
|
+
const val = entry[f.key];
|
|
7063
|
+
if (val !== null && val !== void 0 && typeof val === "object") {
|
|
7064
|
+
if (Array.isArray(val)) {
|
|
7065
|
+
if (val[0]?.url) {
|
|
7066
|
+
const enriched = await enrichMediaAssetNode(strapi, val[0], {
|
|
7067
|
+
defaultAutoMaxW: 800,
|
|
7068
|
+
fileCache
|
|
7069
|
+
});
|
|
7070
|
+
row[f.key] = enriched?.optimized_url || enriched?.url || val[0].url;
|
|
7071
|
+
} else {
|
|
7072
|
+
row[f.key] = `${val.length} item`;
|
|
7073
|
+
}
|
|
7074
|
+
} else if (val.url) {
|
|
7075
|
+
const enriched = await enrichMediaAssetNode(strapi, val, {
|
|
7076
|
+
defaultAutoMaxW: 800,
|
|
7077
|
+
fileCache
|
|
7078
|
+
});
|
|
7079
|
+
row[f.key] = enriched?.optimized_url || enriched?.url || val.url;
|
|
7080
|
+
} else {
|
|
7081
|
+
row[f.key] = "";
|
|
7082
|
+
}
|
|
7083
|
+
} else {
|
|
7084
|
+
row[f.key] = val ?? "";
|
|
7085
|
+
}
|
|
7086
|
+
}
|
|
7087
|
+
return row;
|
|
7088
|
+
})
|
|
7089
|
+
);
|
|
7090
|
+
return {
|
|
7091
|
+
uid,
|
|
7092
|
+
displayName: ct.info?.displayName || uid,
|
|
7093
|
+
availableFields: allowedFields,
|
|
7094
|
+
rows: sanitizedRows
|
|
7095
|
+
};
|
|
7096
|
+
},
|
|
7097
|
+
/**
|
|
7098
|
+
* Batch Entity Cards resolver for `entityCard` Swiper Carousel & Grid modes
|
|
7099
|
+
*/
|
|
7100
|
+
async resolveEntityCardsBatch(params) {
|
|
7101
|
+
const uid = String(params.uid || "api::page.page").trim();
|
|
7102
|
+
if (!uid.startsWith("api::")) return [];
|
|
7103
|
+
const formSvc = strapi.plugin("content-input").service("ci-form");
|
|
7104
|
+
const docIds = Array.isArray(params.documentIds) ? params.documentIds.map((s) => String(s).trim()).filter(Boolean) : [];
|
|
7105
|
+
if (docIds.length > 0) {
|
|
7106
|
+
const results = await Promise.all(
|
|
7107
|
+
docIds.map(
|
|
7108
|
+
(documentId) => formSvc.resolveEntityCard({ uid, documentId }).catch(() => null)
|
|
7109
|
+
)
|
|
7110
|
+
);
|
|
7111
|
+
return results.filter(Boolean);
|
|
7112
|
+
}
|
|
7113
|
+
const limit = clamp(Number(params.limit) || 6, 1, 24);
|
|
7114
|
+
try {
|
|
7115
|
+
const docService = strapi.documents?.(uid);
|
|
7116
|
+
let entries = [];
|
|
7117
|
+
if (docService) {
|
|
7118
|
+
entries = await docService.findMany({ status: "published", limit, sort: "createdAt:desc" });
|
|
7119
|
+
if (!entries.length) {
|
|
7120
|
+
entries = await docService.findMany({ limit, sort: "createdAt:desc" });
|
|
7121
|
+
}
|
|
7122
|
+
} else {
|
|
7123
|
+
entries = await strapi.db.query(uid).findMany({ limit });
|
|
7124
|
+
}
|
|
7125
|
+
const uniqueDocIds = Array.from(
|
|
7126
|
+
new Set(entries.map((e) => e.documentId).filter(Boolean))
|
|
7127
|
+
);
|
|
7128
|
+
const cards = await Promise.all(
|
|
7129
|
+
uniqueDocIds.slice(0, limit).map(
|
|
7130
|
+
(documentId) => formSvc.resolveEntityCard({ uid, documentId }).catch(() => null)
|
|
7131
|
+
)
|
|
7132
|
+
);
|
|
7133
|
+
return cards.filter(Boolean);
|
|
7134
|
+
} catch {
|
|
7135
|
+
return [];
|
|
7136
|
+
}
|
|
7137
|
+
}
|
|
7138
|
+
});
|
|
5264
7139
|
const services = {
|
|
5265
7140
|
"ci-template": ciTemplateService,
|
|
5266
7141
|
"ci-menu": ciMenuService,
|
|
5267
7142
|
"ci-form": ciFormService,
|
|
5268
|
-
"ci-survey": ciSurveyService
|
|
7143
|
+
"ci-survey": ciSurveyService,
|
|
7144
|
+
"ci-color": ciColorService
|
|
5269
7145
|
};
|
|
5270
7146
|
const index = {
|
|
5271
7147
|
register,
|