@ozguraltan/strapi-content-input 1.0.8 → 1.0.10

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.
@@ -121,7 +121,7 @@ const index = {
121
121
  },
122
122
  icon: PluginIcon,
123
123
  components: {
124
- Input: async () => import("./ContentInputField-CKTOutN-.mjs").then((mod) => ({
124
+ Input: async () => import("./ContentInputField-B917gT8j.mjs").then((mod) => ({
125
125
  default: mod.ContentInputField
126
126
  }))
127
127
  },
@@ -124,7 +124,7 @@ const index = {
124
124
  },
125
125
  icon: PluginIcon,
126
126
  components: {
127
- Input: async () => Promise.resolve().then(() => require("./ContentInputField-CLuL3TFr.js")).then((mod) => ({
127
+ Input: async () => Promise.resolve().then(() => require("./ContentInputField-figtXsYp.js")).then((mod) => ({
128
128
  default: mod.ContentInputField
129
129
  }))
130
130
  },
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const index = require("./index-DV4pLrQl.js");
3
+ const index = require("./index-WlNKw5Qo.js");
4
4
  require("react");
5
5
  exports.default = index.index;
@@ -1,4 +1,4 @@
1
- import { i } from "./index-BIwC3VPC.mjs";
1
+ import { i } from "./index-DV8S3QWG.mjs";
2
2
  import "react";
3
3
  export {
4
4
  i as default
@@ -7,5 +7,5 @@ export interface StrapiMediaPickerProps {
7
7
  multiple?: boolean;
8
8
  onSelectMultiple?: (assets: CIMediaAsset[]) => void;
9
9
  }
10
- export declare function mapStrapiFileToAsset(file: any): CIMediaAsset;
10
+ export declare function mapStrapiFileToAsset(file: any, cacheBust?: boolean): CIMediaAsset;
11
11
  export declare const StrapiMediaPicker: React.FC<StrapiMediaPickerProps>;
@@ -0,0 +1 @@
1
+ export declare const SWIPER_BUNDLE_CSS = "/**\n * Swiper 14.4.0\n * Most modern mobile touch slider and framework with hardware accelerated transitions\n * https://swiperjs.com\n *\n * Copyright 2014-2026 Vladimir Kharlampidi\n *\n * Released under the MIT License\n *\n * Released on: October 30, 2026\n */\n\n:root{--swiper-theme-color:#007aff}:host{display:block;margin-left:auto;margin-right:auto;position:relative;z-index:1}.swiper{display:block;list-style:none;margin-left:auto;margin-right:auto;overflow:hidden;padding:0;position:relative;z-index:1}.swiper-vertical>.swiper-wrapper{flex-direction:column}.swiper-wrapper{box-sizing:initial;display:flex;height:100%;position:relative;transition-property:transform;transition-timing-function:var(--swiper-wrapper-transition-timing-function,initial);width:100%;z-index:1}.swiper-android .swiper-slide,.swiper-ios .swiper-slide,.swiper-wrapper{transform:translateZ(0)}.swiper-horizontal{touch-action:pan-y}.swiper-vertical{touch-action:pan-x}.swiper-slide{display:block;flex-shrink:0;height:100%;position:relative;transition-property:transform;width:100%}.swiper-slide-invisible-blank{visibility:hidden}.swiper-autoheight,.swiper-autoheight .swiper-slide{height:auto}.swiper-autoheight .swiper-wrapper{align-items:flex-start;transition-property:transform,height}.swiper-backface-hidden .swiper-slide{backface-visibility:hidden;transform:translateZ(0)}.swiper-3d.swiper-css-mode .swiper-wrapper{perspective:1200px}.swiper-3d .swiper-wrapper{transform-style:preserve-3d}.swiper-3d{perspective:1200px;.swiper-cube-shadow,.swiper-slide{transform-style:preserve-3d}}.swiper-css-mode{>.swiper-wrapper{overflow:auto;scrollbar-width:none;-ms-overflow-style:none;&::-webkit-scrollbar{display:none}}>.swiper-wrapper>.swiper-slide{scroll-snap-align:start start}&.swiper-horizontal{>.swiper-wrapper{scroll-snap-type:x mandatory}>.swiper-wrapper>.swiper-slide:first-child{margin-inline-start:var(--swiper-slides-offset-before);scroll-margin-inline-start:var(--swiper-slides-offset-before)}>.swiper-wrapper>.swiper-slide:last-child{margin-inline-end:var(--swiper-slides-offset-after)}}&.swiper-vertical{>.swiper-wrapper{scroll-snap-type:y mandatory}>.swiper-wrapper>.swiper-slide:first-child{margin-block-start:var(--swiper-slides-offset-before);scroll-margin-block-start:var(--swiper-slides-offset-before)}>.swiper-wrapper>.swiper-slide:last-child{margin-block-end:var(--swiper-slides-offset-after)}}&.swiper-free-mode{>.swiper-wrapper{scroll-snap-type:none}>.swiper-wrapper>.swiper-slide{scroll-snap-align:none}}&.swiper-centered{>.swiper-wrapper:before{content:\"\";flex-shrink:0;order:9999}>.swiper-wrapper>.swiper-slide{scroll-snap-align:center center;scroll-snap-stop:always}}&.swiper-centered.swiper-horizontal{>.swiper-wrapper>.swiper-slide:first-child{margin-inline-start:var(--swiper-centered-offset-before)}>.swiper-wrapper:before{height:100%;min-height:1px;width:var(--swiper-centered-offset-after)}}&.swiper-centered.swiper-vertical{>.swiper-wrapper>.swiper-slide:first-child{margin-block-start:var(--swiper-centered-offset-before)}>.swiper-wrapper:before{height:var(--swiper-centered-offset-after);min-width:1px;width:100%}}}.swiper-3d{.swiper-slide-shadow,.swiper-slide-shadow-bottom,.swiper-slide-shadow-left,.swiper-slide-shadow-right,.swiper-slide-shadow-top{height:100%;left:0;pointer-events:none;position:absolute;top:0;width:100%;z-index:10}.swiper-slide-shadow{background:#00000026}.swiper-slide-shadow-left{background-image:linear-gradient(270deg,#00000080,#0000)}.swiper-slide-shadow-right{background-image:linear-gradient(90deg,#00000080,#0000)}.swiper-slide-shadow-top{background-image:linear-gradient(0deg,#00000080,#0000)}.swiper-slide-shadow-bottom{background-image:linear-gradient(180deg,#00000080,#0000)}}.swiper-lazy-preloader{border:4px solid var(--swiper-preloader-color,var(--swiper-theme-color));border-radius:50%;border-top:4px solid #0000;box-sizing:border-box;height:42px;left:50%;margin-left:-21px;margin-top:-21px;position:absolute;top:50%;transform-origin:50%;width:42px;z-index:10}.swiper-watch-progress .swiper-slide-visible,.swiper:not(.swiper-watch-progress){.swiper-lazy-preloader{animation:swiper-preloader-spin 1s linear infinite}}.swiper-lazy-preloader-white{--swiper-preloader-color:#fff}.swiper-lazy-preloader-black{--swiper-preloader-color:#000}@keyframes swiper-preloader-spin{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.swiper-virtual .swiper-slide{-webkit-backface-visibility:hidden;transform:translateZ(0)}.swiper-virtual.swiper-css-mode{.swiper-wrapper:after{content:\"\";left:0;pointer-events:none;position:absolute;top:0}}.swiper-virtual.swiper-css-mode.swiper-horizontal{.swiper-wrapper:after{height:1px;width:var(--swiper-virtual-size)}}.swiper-virtual.swiper-css-mode.swiper-vertical{.swiper-wrapper:after{height:var(--swiper-virtual-size);width:1px}}:root{--swiper-navigation-size:44px}.swiper-button-next,.swiper-button-prev{align-items:center;color:var(--swiper-navigation-color,var(--swiper-theme-color));cursor:pointer;display:flex;height:var(--swiper-navigation-size);justify-content:center;position:absolute;width:var(--swiper-navigation-size);z-index:10;&.swiper-button-disabled{cursor:auto;opacity:.35;pointer-events:none}&.swiper-button-hidden{cursor:auto;opacity:0;pointer-events:none}.swiper-navigation-disabled &{display:none!important}::slotted(svg),svg{height:100%;object-fit:contain;transform-origin:center;width:100%;fill:currentColor;pointer-events:none}}.swiper-button-lock{display:none}.swiper-button-next,.swiper-button-prev{margin-top:calc(0px - var(--swiper-navigation-size)/2);top:var(--swiper-navigation-top-offset,50%)}.swiper-button-prev{left:var(--swiper-navigation-sides-offset,4px);right:auto;.swiper-navigation-icon,::slotted(.swiper-navigation-icon){transform:rotate(180deg)}}.swiper-button-next{left:auto;right:var(--swiper-navigation-sides-offset,4px)}.swiper-horizontal{.swiper-button-next,.swiper-button-prev,~.swiper-button-next,~.swiper-button-prev{margin-left:0;margin-top:calc(0px - var(--swiper-navigation-size)/2);top:var(--swiper-navigation-top-offset,50%)}&.swiper-rtl .swiper-button-next,&.swiper-rtl~.swiper-button-next,&~.swiper-button-prev,.swiper-button-prev{left:var(--swiper-navigation-sides-offset,4px);right:auto}&.swiper-rtl .swiper-button-prev,&.swiper-rtl~.swiper-button-prev,&~.swiper-button-next,.swiper-button-next{left:auto;right:var(--swiper-navigation-sides-offset,4px)}&.swiper-rtl .swiper-button-next,&.swiper-rtl~.swiper-button-next,&~.swiper-button-prev,.swiper-button-prev{.swiper-navigation-icon,::slotted(.swiper-navigation-icon){transform:rotate(180deg)}}&.swiper-rtl .swiper-button-prev,&.swiper-rtl~.swiper-button-prev{.swiper-navigation-icon,::slotted(.swiper-navigation-icon){transform:rotate(0deg)}}}.swiper-vertical{.swiper-button-next,.swiper-button-prev,~.swiper-button-next,~.swiper-button-prev{left:var(--swiper-navigation-top-offset,50%);margin-left:calc(0px - var(--swiper-navigation-size)/2);margin-top:0;right:auto}.swiper-button-prev,~.swiper-button-prev{bottom:auto;top:var(--swiper-navigation-sides-offset,4px);.swiper-navigation-icon,::slotted(.swiper-navigation-icon){transform:rotate(-90deg)}}.swiper-button-next,~.swiper-button-next{bottom:var(--swiper-navigation-sides-offset,4px);top:auto;.swiper-navigation-icon,::slotted(.swiper-navigation-icon){transform:rotate(90deg)}}}.swiper-pagination{position:absolute;text-align:center;transform:translateZ(0);transition:opacity .3s;z-index:10;&.swiper-pagination-hidden{opacity:0}&.swiper-pagination-disabled,.swiper-pagination-disabled>&{display:none!important}}.swiper-horizontal>.swiper-pagination-bullets,.swiper-pagination-bullets.swiper-pagination-horizontal,.swiper-pagination-custom,.swiper-pagination-fraction{bottom:var(--swiper-pagination-bottom,8px);left:0;top:var(--swiper-pagination-top,auto);width:100%}.swiper-pagination-bullets-dynamic{font-size:0;overflow:hidden;.swiper-pagination-bullet{position:relative;transform:scale(.33)}.swiper-pagination-bullet-active,.swiper-pagination-bullet-active-main{transform:scale(1)}.swiper-pagination-bullet-active-prev{transform:scale(.66)}.swiper-pagination-bullet-active-prev-prev{transform:scale(.33)}.swiper-pagination-bullet-active-next{transform:scale(.66)}.swiper-pagination-bullet-active-next-next{transform:scale(.33)}}.swiper-pagination-bullet{background:var(--swiper-pagination-bullet-inactive-color,#000);border-radius:var(--swiper-pagination-bullet-border-radius,50%);display:inline-block;height:var(--swiper-pagination-bullet-height,var(--swiper-pagination-bullet-size,8px));opacity:var(--swiper-pagination-bullet-inactive-opacity,.2);width:var(--swiper-pagination-bullet-width,var(--swiper-pagination-bullet-size,8px));button&{appearance:none;border:none;box-shadow:none;margin:0;padding:0}.swiper-pagination-clickable &{cursor:pointer}&:only-child{display:none!important}}.swiper-pagination-bullet-active{background:var(--swiper-pagination-color,var(--swiper-theme-color));opacity:var(--swiper-pagination-bullet-opacity,1)}.swiper-pagination-vertical.swiper-pagination-bullets,.swiper-vertical>.swiper-pagination-bullets{left:var(--swiper-pagination-left,auto);right:var(--swiper-pagination-right,8px);top:50%;transform:translate3d(0,-50%,0);.swiper-pagination-bullet{display:block;margin:var(--swiper-pagination-bullet-vertical-gap,6px) 0}&.swiper-pagination-bullets-dynamic{top:50%;transform:translateY(-50%);width:8px;.swiper-pagination-bullet{display:inline-block;transition:transform .2s,top .2s}}}.swiper-horizontal>.swiper-pagination-bullets,.swiper-pagination-horizontal.swiper-pagination-bullets{.swiper-pagination-bullet{margin:0 var(--swiper-pagination-bullet-horizontal-gap,4px)}&.swiper-pagination-bullets-dynamic{left:50%;transform:translateX(-50%);white-space:nowrap;.swiper-pagination-bullet{transition:transform .2s,left .2s}}}.swiper-horizontal.swiper-rtl>.swiper-pagination-bullets-dynamic .swiper-pagination-bullet{transition:transform .2s,right .2s}.swiper-pagination-fraction{color:var(--swiper-pagination-fraction-color,inherit)}.swiper-pagination-progressbar{background:var(--swiper-pagination-progressbar-bg-color,#00000040);position:absolute;.swiper-pagination-progressbar-fill{background:var(--swiper-pagination-color,var(--swiper-theme-color));height:100%;left:0;position:absolute;top:0;transform:scale(0);transform-origin:left top;width:100%}.swiper-rtl & .swiper-pagination-progressbar-fill{transform-origin:right top}&.swiper-pagination-horizontal,&.swiper-pagination-vertical.swiper-pagination-progressbar-opposite,.swiper-horizontal>&,.swiper-vertical>&.swiper-pagination-progressbar-opposite{height:var(--swiper-pagination-progressbar-size,4px);left:0;top:0;width:100%}&.swiper-pagination-horizontal.swiper-pagination-progressbar-opposite,&.swiper-pagination-vertical,.swiper-horizontal>&.swiper-pagination-progressbar-opposite,.swiper-vertical>&{height:100%;left:0;top:0;width:var(--swiper-pagination-progressbar-size,4px)}}.swiper-pagination-lock{display:none}.swiper-scrollbar{background:var(--swiper-scrollbar-bg-color,#0000001a);border-radius:var(--swiper-scrollbar-border-radius,10px);position:relative;touch-action:none;&.swiper-scrollbar-disabled,.swiper-scrollbar-disabled>&{display:none!important}&.swiper-scrollbar-horizontal,.swiper-horizontal>&{bottom:var(--swiper-scrollbar-bottom,4px);height:var(--swiper-scrollbar-size,4px);left:var(--swiper-scrollbar-sides-offset,1%);position:absolute;top:var(--swiper-scrollbar-top,auto);width:calc(100% - var(--swiper-scrollbar-sides-offset, 1%)*2);z-index:50}&.swiper-scrollbar-vertical,.swiper-vertical>&{height:calc(100% - var(--swiper-scrollbar-sides-offset, 1%)*2);left:var(--swiper-scrollbar-left,auto);position:absolute;right:var(--swiper-scrollbar-right,4px);top:var(--swiper-scrollbar-sides-offset,1%);width:var(--swiper-scrollbar-size,4px);z-index:50}}.swiper-scrollbar-drag{background:var(--swiper-scrollbar-drag-bg-color,#00000080);border-radius:var(--swiper-scrollbar-border-radius,10px);height:100%;left:0;position:relative;top:0;width:100%}.swiper-scrollbar-cursor-drag{cursor:move}.swiper-scrollbar-lock{display:none}.swiper-zoom-container{align-items:center;display:flex;height:100%;justify-content:center;text-align:center;width:100%;>canvas,>img,>svg{max-height:100%;max-width:100%;object-fit:contain}}.swiper-slide-zoomed{cursor:move;touch-action:none}.swiper .swiper-notification{left:0;opacity:0;pointer-events:none;position:absolute;top:0;z-index:-1000}.swiper-free-mode>.swiper-wrapper{margin:0 auto;transition-timing-function:ease-out}.swiper-grid>.swiper-wrapper{flex-wrap:wrap}.swiper-grid-column>.swiper-wrapper{flex-direction:column;flex-wrap:wrap}.swiper-fade{&.swiper-free-mode{.swiper-slide{transition-timing-function:ease-out}}.swiper-slide{pointer-events:none;transition-property:opacity;.swiper-slide{pointer-events:none}}.swiper-slide-active{pointer-events:auto;& .swiper-slide-active{pointer-events:auto}}}.swiper.swiper-cube{overflow:visible}.swiper-cube{.swiper-slide{backface-visibility:hidden;height:100%;pointer-events:none;transform-origin:0 0;visibility:hidden;width:100%;z-index:1;.swiper-slide{pointer-events:none}}&.swiper-rtl .swiper-slide{transform-origin:100% 0}.swiper-slide-active{&,& .swiper-slide-active{pointer-events:auto}}.swiper-slide-active,.swiper-slide-next,.swiper-slide-prev{pointer-events:auto;visibility:visible}.swiper-cube-shadow{bottom:0;height:100%;left:0;opacity:.6;position:absolute;width:100%;z-index:0;&:before{background:#000;bottom:0;content:\"\";filter:blur(50px);left:0;position:absolute;right:0;top:0}}}.swiper-cube{.swiper-slide-next+.swiper-slide{pointer-events:auto;visibility:visible}}.swiper-cube{.swiper-slide-shadow-cube.swiper-slide-shadow-bottom,.swiper-slide-shadow-cube.swiper-slide-shadow-left,.swiper-slide-shadow-cube.swiper-slide-shadow-right,.swiper-slide-shadow-cube.swiper-slide-shadow-top{backface-visibility:hidden;z-index:0}}.swiper.swiper-flip{overflow:visible}.swiper-flip{.swiper-slide{backface-visibility:hidden;pointer-events:none;z-index:1;.swiper-slide{pointer-events:none}}.swiper-slide-active{&,& .swiper-slide-active{pointer-events:auto}}}.swiper-flip{.swiper-slide-shadow-flip.swiper-slide-shadow-bottom,.swiper-slide-shadow-flip.swiper-slide-shadow-left,.swiper-slide-shadow-flip.swiper-slide-shadow-right,.swiper-slide-shadow-flip.swiper-slide-shadow-top{backface-visibility:hidden;z-index:0}}.swiper-creative{.swiper-slide{backface-visibility:hidden;overflow:hidden;transition-property:transform,opacity,height}}.swiper.swiper-cards{overflow:visible}.swiper-cards{.swiper-slide{backface-visibility:hidden;overflow:hidden;transform-origin:center bottom}}";
@@ -1,5 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const crypto = require("crypto");
4
+ const fs = require("fs");
5
+ const module$1 = require("module");
6
+ const os = require("os");
7
+ const path = require("path");
8
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
9
+ const crypto__default = /* @__PURE__ */ _interopDefault(crypto);
10
+ const fs__default = /* @__PURE__ */ _interopDefault(fs);
11
+ const os__default = /* @__PURE__ */ _interopDefault(os);
12
+ const path__default = /* @__PURE__ */ _interopDefault(path);
3
13
  const register = ({ strapi }) => {
4
14
  strapi.customFields.register({
5
15
  name: "content-input",
@@ -158,17 +168,435 @@ const ciMenuController = ({ strapi }) => ({
158
168
  try {
159
169
  const files = await strapi.db.query("plugin::upload.file").findMany({
160
170
  orderBy: { createdAt: "desc" },
161
- limit: 120
171
+ populate: { folder: true },
172
+ limit: 500
162
173
  });
163
- ctx.body = { data: Array.isArray(files) ? files : [] };
174
+ let folders = [];
175
+ try {
176
+ folders = await strapi.db.query("plugin::upload.folder").findMany({
177
+ orderBy: { name: "asc" },
178
+ populate: { parent: true }
179
+ });
180
+ } catch {
181
+ folders = [];
182
+ }
183
+ ctx.body = {
184
+ data: Array.isArray(files) ? files : [],
185
+ folders: Array.isArray(folders) ? folders : []
186
+ };
164
187
  } catch (err) {
165
188
  ctx.throw(500, err);
166
189
  }
167
190
  }
168
191
  });
192
+ function getSharp() {
193
+ const req = typeof require !== "undefined" ? require : module$1.createRequire(path__default.default.join(process.cwd(), "package.json"));
194
+ return req("sharp");
195
+ }
196
+ function getCacheDir(strapi) {
197
+ const rootDir = strapi?.dirs?.app?.root || process.cwd();
198
+ const dir = path__default.default.join(rootDir, ".cache", "content-input-images");
199
+ if (!fs__default.default.existsSync(dir)) {
200
+ fs__default.default.mkdirSync(dir, { recursive: true });
201
+ }
202
+ return dir;
203
+ }
204
+ async function loadSourceBuffer(strapi, src) {
205
+ const publicDir = strapi?.dirs?.static?.public || path__default.default.join(process.cwd(), "public");
206
+ if (src.startsWith("/")) {
207
+ const cleanRel = decodeURIComponent(src.split("?")[0]).replace(/^\/+/, "");
208
+ const fullPath = path__default.default.resolve(publicDir, cleanRel);
209
+ const resolvedPublic = path__default.default.resolve(publicDir);
210
+ if (!fullPath.startsWith(resolvedPublic)) {
211
+ throw new Error("Invalid local file path");
212
+ }
213
+ if (!fs__default.default.existsSync(fullPath)) {
214
+ throw new Error(`File not found: ${src}`);
215
+ }
216
+ const buffer = await fs__default.default.promises.readFile(fullPath);
217
+ const ext = path__default.default.extname(fullPath).toLowerCase();
218
+ const mime = ext === ".png" ? "image/png" : ext === ".webp" ? "image/webp" : ext === ".avif" ? "image/avif" : ext === ".gif" ? "image/gif" : "image/jpeg";
219
+ return { buffer, mime };
220
+ }
221
+ if (/^https?:\/\//i.test(src)) {
222
+ const parsed = new URL(src);
223
+ if ((parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1") && parsed.pathname.startsWith("/uploads/")) {
224
+ const cleanRel = decodeURIComponent(parsed.pathname).replace(/^\/+/, "");
225
+ const fullPath = path__default.default.resolve(publicDir, cleanRel);
226
+ if (fs__default.default.existsSync(fullPath)) {
227
+ const buffer = await fs__default.default.promises.readFile(fullPath);
228
+ return { buffer, mime: "image/jpeg" };
229
+ }
230
+ }
231
+ const res = await fetch(src);
232
+ if (!res.ok) {
233
+ throw new Error(`Failed to fetch remote image (${res.status})`);
234
+ }
235
+ const contentType = res.headers.get("content-type") || "image/jpeg";
236
+ const arr = await res.arrayBuffer();
237
+ return { buffer: Buffer.from(arr), mime: contentType };
238
+ }
239
+ throw new Error("Unsupported image source URL");
240
+ }
241
+ const ciImageController = ({ strapi }) => ({
242
+ /**
243
+ * GET /api/content-input/image & GET /content-input/image
244
+ * On-the-fly image scaling & cropping powered by sharp with disk + CDN HTTP caching.
245
+ */
246
+ async processImage(ctx) {
247
+ try {
248
+ const query = ctx.query || {};
249
+ const src = String(query.src || query.url || "").trim();
250
+ if (!src) {
251
+ return ctx.badRequest("Missing src parameter");
252
+ }
253
+ const processMode = String(query.process || "fit").toLowerCase();
254
+ const w = Math.min(3840, Math.max(0, parseInt(String(query.w || query.cWidth || "0"), 10) || 0));
255
+ const h = Math.min(3840, Math.max(0, parseInt(String(query.h || query.cHeight || "0"), 10) || 0));
256
+ const q = Math.min(100, Math.max(20, parseInt(String(query.q || "85"), 10) || 85));
257
+ const rotate = parseInt(String(query.rotate || "0"), 10) || 0;
258
+ const cx = parseInt(String(query.x || "0"), 10) || 0;
259
+ const cy = parseInt(String(query.y || "0"), 10) || 0;
260
+ const cw = parseInt(String(query.cw || "0"), 10) || 0;
261
+ const ch = parseInt(String(query.ch || "0"), 10) || 0;
262
+ const requestedFormat = String(query.format || "").toLowerCase();
263
+ const cacheKeyRaw = JSON.stringify({
264
+ src,
265
+ processMode,
266
+ w,
267
+ h,
268
+ q,
269
+ rotate,
270
+ cx,
271
+ cy,
272
+ cw,
273
+ ch,
274
+ requestedFormat
275
+ });
276
+ const hash = crypto__default.default.createHash("sha1").update(cacheKeyRaw).digest("hex");
277
+ const etag = `"ci-${hash}"`;
278
+ if (ctx.req.headers["if-none-match"] === etag) {
279
+ ctx.status = 304;
280
+ return;
281
+ }
282
+ const cacheDir = getCacheDir(strapi);
283
+ const metaPath = path__default.default.join(cacheDir, `${hash}.json`);
284
+ const binPath = path__default.default.join(cacheDir, `${hash}.bin`);
285
+ if (fs__default.default.existsSync(metaPath) && fs__default.default.existsSync(binPath)) {
286
+ const meta = JSON.parse(await fs__default.default.promises.readFile(metaPath, "utf8"));
287
+ const cachedBuffer = await fs__default.default.promises.readFile(binPath);
288
+ ctx.set("Content-Type", meta.contentType || "image/jpeg");
289
+ ctx.set("Cache-Control", "public, max-age=31536000, immutable");
290
+ ctx.set("ETag", etag);
291
+ ctx.set("Access-Control-Allow-Origin", "*");
292
+ ctx.body = cachedBuffer;
293
+ return;
294
+ }
295
+ const { buffer: sourceBuffer, mime: sourceMime } = await loadSourceBuffer(strapi, src);
296
+ const sharp = getSharp();
297
+ let pipeline = sharp(sourceBuffer, { failOn: "none" }).rotate();
298
+ if (rotate && [90, 180, 270, -90].includes(rotate)) {
299
+ pipeline = pipeline.rotate(rotate);
300
+ }
301
+ if (cw > 0 && ch > 0) {
302
+ pipeline = pipeline.extract({
303
+ left: Math.max(0, cx),
304
+ top: Math.max(0, cy),
305
+ width: cw,
306
+ height: ch
307
+ });
308
+ }
309
+ if (processMode === "fit" && w > 0 && h > 0) {
310
+ pipeline = pipeline.resize(w, h, {
311
+ fit: "cover",
312
+ position: "centre",
313
+ withoutEnlargement: false
314
+ });
315
+ } else if (processMode === "widen" && w > 0) {
316
+ pipeline = pipeline.resize(w, null, {
317
+ fit: "inside",
318
+ withoutEnlargement: false
319
+ });
320
+ } else if (w > 0 || h > 0) {
321
+ pipeline = pipeline.resize(w || null, h || null, {
322
+ fit: "inside",
323
+ withoutEnlargement: true
324
+ });
325
+ }
326
+ let outContentType = sourceMime;
327
+ if (requestedFormat === "webp" || sourceMime === "image/webp") {
328
+ pipeline = pipeline.webp({ quality: q });
329
+ outContentType = "image/webp";
330
+ } else if (requestedFormat === "avif" || sourceMime === "image/avif") {
331
+ pipeline = pipeline.avif({ quality: q });
332
+ outContentType = "image/avif";
333
+ } else if (requestedFormat === "png" || sourceMime === "image/png") {
334
+ pipeline = pipeline.png({ quality: q });
335
+ outContentType = "image/png";
336
+ } else {
337
+ pipeline = pipeline.jpeg({ quality: q, mozjpeg: true });
338
+ outContentType = "image/jpeg";
339
+ }
340
+ const outputBuffer = await pipeline.toBuffer();
341
+ let providerUrl;
342
+ try {
343
+ const cleanSrc = src.split("?")[0];
344
+ const existingFile = await strapi.db.query("plugin::upload.file").findOne({
345
+ where: { url: cleanSrc }
346
+ });
347
+ if (existingFile && existingFile.id) {
348
+ const formatKey = `ci_${processMode}_${w}x${h}${rotate ? `_r${rotate}` : ""}`;
349
+ const existingFormat = existingFile.formats?.[formatKey];
350
+ if (existingFormat?.url) {
351
+ providerUrl = existingFormat.url;
352
+ } else {
353
+ const outMeta = await sharp(outputBuffer).metadata();
354
+ const ext = outContentType === "image/png" ? ".png" : outContentType === "image/webp" ? ".webp" : outContentType === "image/avif" ? ".avif" : ".jpg";
355
+ const variantHash = `${formatKey}_${existingFile.hash || hash.slice(0, 10)}`;
356
+ const variantName = `${formatKey}_${existingFile.name || "image"}`;
357
+ const tmpVariantPath = path__default.default.join(os__default.default.tmpdir(), `${variantHash}${ext}`);
358
+ await fs__default.default.promises.writeFile(tmpVariantPath, outputBuffer);
359
+ try {
360
+ const variantFile = {
361
+ name: variantName,
362
+ hash: variantHash,
363
+ ext,
364
+ mime: outContentType,
365
+ filepath: tmpVariantPath,
366
+ path: existingFile.path || null,
367
+ getStream: () => fs__default.default.createReadStream(tmpVariantPath),
368
+ width: outMeta.width || w || void 0,
369
+ height: outMeta.height || h || void 0,
370
+ size: Math.round(outputBuffer.length / 1e3 * 100) / 100,
371
+ sizeInBytes: outputBuffer.length
372
+ };
373
+ const providerService = strapi.plugin("upload").service("provider");
374
+ if (providerService && typeof providerService.upload === "function") {
375
+ await providerService.upload(variantFile);
376
+ providerUrl = variantFile.url;
377
+ const { filepath: _fp, getStream: _gs, ...serializableFormat } = variantFile;
378
+ const nextFormats = {
379
+ ...existingFile.formats || {},
380
+ [formatKey]: serializableFormat
381
+ };
382
+ await strapi.db.query("plugin::upload.file").update({
383
+ where: { id: existingFile.id },
384
+ data: { formats: nextFormats }
385
+ });
386
+ }
387
+ } finally {
388
+ await fs__default.default.promises.rm(tmpVariantPath, { force: true }).catch(() => void 0);
389
+ }
390
+ }
391
+ }
392
+ } catch {
393
+ }
394
+ await fs__default.default.promises.writeFile(binPath, outputBuffer);
395
+ await fs__default.default.promises.writeFile(
396
+ metaPath,
397
+ JSON.stringify({
398
+ contentType: outContentType,
399
+ size: outputBuffer.length,
400
+ providerUrl
401
+ })
402
+ );
403
+ ctx.set("Content-Type", outContentType);
404
+ ctx.set("Cache-Control", "public, max-age=31536000, immutable");
405
+ ctx.set("ETag", etag);
406
+ ctx.set("Access-Control-Allow-Origin", "*");
407
+ if (providerUrl) {
408
+ ctx.set("X-Content-Input-CDN-Url", providerUrl);
409
+ }
410
+ ctx.body = outputBuffer;
411
+ } catch (err) {
412
+ ctx.throw(400, err?.message || "Image processing error");
413
+ }
414
+ },
415
+ /**
416
+ * POST /content-input/media/crop
417
+ * Interactive crop & rotate using sharp on the backend (works seamlessly with local disk AND remote CDNs).
418
+ * Supports mode: 'replace' (crops original asset in Media Library) or 'duplicate' (saves as new asset).
419
+ */
420
+ async cropMedia(ctx) {
421
+ const tmpDir = await fs__default.default.promises.mkdtemp(path__default.default.join(os__default.default.tmpdir(), "ci-crop-"));
422
+ try {
423
+ const body = ctx.request.body || {};
424
+ const id = body.id;
425
+ const mode = body.mode === "replace" ? "replace" : "duplicate";
426
+ const x = Math.max(0, Math.round(Number(body.x) || 0));
427
+ const y = Math.max(0, Math.round(Number(body.y) || 0));
428
+ const width = Math.max(1, Math.round(Number(body.width) || 0));
429
+ const height = Math.max(1, Math.round(Number(body.height) || 0));
430
+ const rotate = Number(body.rotate) || 0;
431
+ const resizeWidth = Math.max(0, Math.round(Number(body.resizeWidth) || 0));
432
+ const resizeHeight = Math.max(0, Math.round(Number(body.resizeHeight) || 0));
433
+ if (!id) {
434
+ return ctx.badRequest("Asset id is required");
435
+ }
436
+ const existingFile = await strapi.db.query("plugin::upload.file").findOne({
437
+ where: { id: Number(id) },
438
+ populate: { folder: true }
439
+ });
440
+ if (!existingFile) {
441
+ return ctx.notFound("Media asset not found");
442
+ }
443
+ const { buffer: sourceBuffer } = await loadSourceBuffer(strapi, existingFile.url);
444
+ const sharp = getSharp();
445
+ let pipeline = sharp(sourceBuffer, { failOn: "none" }).rotate();
446
+ if (rotate && [90, 180, 270, -90].includes(rotate)) {
447
+ pipeline = pipeline.rotate(rotate);
448
+ }
449
+ const meta = await pipeline.metadata();
450
+ const imgW = meta.width || width;
451
+ const imgH = meta.height || height;
452
+ const safeLeft = Math.min(x, Math.max(0, imgW - 1));
453
+ const safeTop = Math.min(y, Math.max(0, imgH - 1));
454
+ const safeWidth = Math.min(width, imgW - safeLeft);
455
+ const safeHeight = Math.min(height, imgH - safeTop);
456
+ if (safeWidth > 0 && safeHeight > 0) {
457
+ pipeline = pipeline.extract({
458
+ left: safeLeft,
459
+ top: safeTop,
460
+ width: safeWidth,
461
+ height: safeHeight
462
+ });
463
+ }
464
+ if (resizeWidth > 0 || resizeHeight > 0) {
465
+ pipeline = pipeline.resize(resizeWidth || null, resizeHeight || null, {
466
+ fit: resizeWidth > 0 && resizeHeight > 0 ? "fill" : "inside"
467
+ });
468
+ }
469
+ const ext = (existingFile.ext || ".jpg").toLowerCase();
470
+ const mime = existingFile.mime || "image/jpeg";
471
+ if (ext === ".png" || mime === "image/png") {
472
+ pipeline = pipeline.png({ quality: 92 });
473
+ } else if (ext === ".webp" || mime === "image/webp") {
474
+ pipeline = pipeline.webp({ quality: 90 });
475
+ } else {
476
+ pipeline = pipeline.jpeg({ quality: 90, mozjpeg: true });
477
+ }
478
+ const croppedBuffer = await pipeline.toBuffer();
479
+ const baseName = path__default.default.basename(existingFile.name || "image", existingFile.ext || ext);
480
+ const targetFileName = mode === "duplicate" ? `${body.name || `${baseName}-cropped`}${ext.startsWith(".") ? ext : `.${ext}`}` : existingFile.name || `${baseName}${ext}`;
481
+ const tmpFilePath = path__default.default.join(tmpDir, targetFileName);
482
+ await fs__default.default.promises.writeFile(tmpFilePath, croppedBuffer);
483
+ const uploadService = strapi.plugin("upload").service("upload");
484
+ const fileInfo = {
485
+ name: targetFileName,
486
+ alternativeText: body.alternativeText !== void 0 ? body.alternativeText : existingFile.alternativeText || "",
487
+ caption: body.caption !== void 0 ? body.caption : existingFile.caption || "",
488
+ folder: existingFile.folder?.id ?? existingFile.folder ?? null
489
+ };
490
+ const fileObj = {
491
+ filepath: tmpFilePath,
492
+ originalFilename: targetFileName,
493
+ mimetype: mime,
494
+ detectedMimeType: mime,
495
+ size: croppedBuffer.length
496
+ };
497
+ const user = ctx.state?.user;
498
+ let resultFile;
499
+ if (mode === "replace") {
500
+ resultFile = await uploadService.replace(
501
+ existingFile.id,
502
+ {
503
+ data: { fileInfo },
504
+ file: fileObj
505
+ },
506
+ { user }
507
+ );
508
+ } else {
509
+ const uploaded = await uploadService.upload(
510
+ {
511
+ data: { fileInfo },
512
+ files: [fileObj]
513
+ },
514
+ { user }
515
+ );
516
+ resultFile = Array.isArray(uploaded) ? uploaded[0] : uploaded;
517
+ }
518
+ ctx.body = { data: resultFile };
519
+ } catch (err) {
520
+ ctx.throw(500, err?.message || "Failed to crop media asset");
521
+ } finally {
522
+ try {
523
+ await fs__default.default.promises.rm(tmpDir, { recursive: true, force: true });
524
+ } catch {
525
+ }
526
+ }
527
+ },
528
+ /**
529
+ * PUT /content-input/media/:id
530
+ * Update file metadata (name, alternativeText, caption, folder) in Strapi Media Library.
531
+ */
532
+ async updateMediaInfo(ctx) {
533
+ try {
534
+ const id = Number(ctx.params?.id);
535
+ if (!id) return ctx.badRequest("Asset id is required");
536
+ const { name, alternativeText, caption, folder } = ctx.request.body || {};
537
+ const uploadService = strapi.plugin("upload").service("upload");
538
+ const updated = await uploadService.updateFileInfo(
539
+ id,
540
+ {
541
+ name,
542
+ alternativeText,
543
+ caption,
544
+ folder: folder !== void 0 ? folder : void 0
545
+ },
546
+ { user: ctx.state?.user }
547
+ );
548
+ ctx.body = { data: updated };
549
+ } catch (err) {
550
+ ctx.throw(500, err?.message || "Failed to update media info");
551
+ }
552
+ },
553
+ /**
554
+ * DELETE /content-input/media/:id
555
+ * Delete file from Strapi Media Library & configured upload provider (local or CDN).
556
+ */
557
+ async deleteMedia(ctx) {
558
+ try {
559
+ const id = Number(ctx.params?.id);
560
+ if (!id) return ctx.badRequest("Asset id is required");
561
+ const existingFile = await strapi.db.query("plugin::upload.file").findOne({
562
+ where: { id }
563
+ });
564
+ if (!existingFile) return ctx.notFound("Media asset not found");
565
+ const uploadService = strapi.plugin("upload").service("upload");
566
+ const removed = await uploadService.remove(existingFile);
567
+ ctx.body = { data: removed };
568
+ } catch (err) {
569
+ ctx.throw(500, err?.message || "Failed to delete media asset");
570
+ }
571
+ },
572
+ /**
573
+ * POST /content-input/media/folder
574
+ * Create a new folder in Strapi Media Library.
575
+ */
576
+ async createFolder(ctx) {
577
+ try {
578
+ const { name, parent } = ctx.request.body || {};
579
+ if (!name || !String(name).trim()) {
580
+ return ctx.badRequest("Folder name is required");
581
+ }
582
+ const folderService = strapi.plugin("upload").service("folder");
583
+ const created = await folderService.create(
584
+ {
585
+ name: String(name).trim(),
586
+ parent: parent ? Number(parent) : null
587
+ },
588
+ { user: ctx.state?.user }
589
+ );
590
+ ctx.body = { data: created };
591
+ } catch (err) {
592
+ ctx.throw(500, err?.message || "Failed to create folder");
593
+ }
594
+ }
595
+ });
169
596
  const controllers = {
170
597
  "ci-template": ciTemplateController,
171
- "ci-menu": ciMenuController
598
+ "ci-menu": ciMenuController,
599
+ "ci-image": ciImageController
172
600
  };
173
601
  const routes = {
174
602
  admin: {
@@ -245,6 +673,61 @@ const routes = {
245
673
  config: {
246
674
  policies: []
247
675
  }
676
+ },
677
+ {
678
+ method: "POST",
679
+ path: "/media/crop",
680
+ handler: "ci-image.cropMedia",
681
+ config: {
682
+ policies: []
683
+ }
684
+ },
685
+ {
686
+ method: "PUT",
687
+ path: "/media/:id",
688
+ handler: "ci-image.updateMediaInfo",
689
+ config: {
690
+ policies: []
691
+ }
692
+ },
693
+ {
694
+ method: "DELETE",
695
+ path: "/media/:id",
696
+ handler: "ci-image.deleteMedia",
697
+ config: {
698
+ policies: []
699
+ }
700
+ },
701
+ {
702
+ method: "POST",
703
+ path: "/media/folder",
704
+ handler: "ci-image.createFolder",
705
+ config: {
706
+ policies: []
707
+ }
708
+ },
709
+ {
710
+ method: "GET",
711
+ path: "/image",
712
+ handler: "ci-image.processImage",
713
+ config: {
714
+ auth: false,
715
+ policies: []
716
+ }
717
+ }
718
+ ]
719
+ },
720
+ "content-api": {
721
+ type: "content-api",
722
+ routes: [
723
+ {
724
+ method: "GET",
725
+ path: "/image",
726
+ handler: "ci-image.processImage",
727
+ config: {
728
+ auth: false,
729
+ policies: []
730
+ }
248
731
  }
249
732
  ]
250
733
  }