simple-strapi 1.0.0-alpha.25 → 1.0.0-alpha.26
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/dist/client.d.ts +0 -2
- package/dist/client.js +1 -70
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -139,7 +139,6 @@ declare class Client {
|
|
|
139
139
|
data: any;
|
|
140
140
|
meta: any;
|
|
141
141
|
}>;
|
|
142
|
-
private getOrCreateFolder;
|
|
143
142
|
/**
|
|
144
143
|
* Carica un file sulla Media Library di Strapi.
|
|
145
144
|
*
|
|
@@ -162,7 +161,6 @@ declare class Client {
|
|
|
162
161
|
ref?: string;
|
|
163
162
|
refId?: string | number;
|
|
164
163
|
field?: string;
|
|
165
|
-
path?: string;
|
|
166
164
|
headers?: Record<string, string>;
|
|
167
165
|
}): Promise<ZodMediaType[]>;
|
|
168
166
|
}
|
package/dist/client.js
CHANGED
|
@@ -4,7 +4,7 @@ import fetch from "node-fetch";
|
|
|
4
4
|
import qs from "qs";
|
|
5
5
|
import z from "zod";
|
|
6
6
|
import { defaultStrapiFields, schemaToParser } from "./utils/schema";
|
|
7
|
-
import { zodMediaSchema } from "./fields/media";
|
|
7
|
+
import { zodMediaSchema, } from "./fields/media";
|
|
8
8
|
class Client {
|
|
9
9
|
static async create(endpoint, { auth, ...options } = {}) {
|
|
10
10
|
const endpointURL = new URL(endpoint);
|
|
@@ -389,68 +389,6 @@ class Client {
|
|
|
389
389
|
* AUTO GENERATED - upload method
|
|
390
390
|
* ==========================================
|
|
391
391
|
*/
|
|
392
|
-
async getOrCreateFolder(folderPath) {
|
|
393
|
-
const segments = folderPath.split("/").filter(Boolean);
|
|
394
|
-
let currentParentId = null;
|
|
395
|
-
for (const segment of segments) {
|
|
396
|
-
const params = currentParentId === null
|
|
397
|
-
? { filters: { name: { $eq: segment }, parent: { $null: true } } }
|
|
398
|
-
: { filters: { name: { $eq: segment }, parent: { id: { $eq: currentParentId } } } };
|
|
399
|
-
const listURL = Client.getRequestURL({
|
|
400
|
-
origin: this.origin,
|
|
401
|
-
pathname: join(this.pathname, "upload/folders"),
|
|
402
|
-
params,
|
|
403
|
-
});
|
|
404
|
-
const listResponse = await fetch(listURL, {
|
|
405
|
-
method: "GET",
|
|
406
|
-
headers: this.getAuthorizedHeaders(),
|
|
407
|
-
});
|
|
408
|
-
if (!listResponse.ok) {
|
|
409
|
-
const errorBody = await listResponse.json().catch(() => ({}));
|
|
410
|
-
throw createSimpleException({
|
|
411
|
-
code: listResponse.status,
|
|
412
|
-
message: errorBody.error?.message || listResponse.statusText,
|
|
413
|
-
type: "error",
|
|
414
|
-
source: "strapi-utils/client.ts",
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
const { data: folders } = z
|
|
418
|
-
.object({ data: z.array(z.object({ id: z.number() }).loose()) })
|
|
419
|
-
.parse(await listResponse.json());
|
|
420
|
-
if (folders.length > 0) {
|
|
421
|
-
currentParentId = folders[0].id;
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
const createURL = Client.getRequestURL({
|
|
425
|
-
origin: this.origin,
|
|
426
|
-
pathname: join(this.pathname, "upload/folders"),
|
|
427
|
-
params: {},
|
|
428
|
-
});
|
|
429
|
-
const createBody = currentParentId === null
|
|
430
|
-
? { name: segment }
|
|
431
|
-
: { name: segment, parent: currentParentId };
|
|
432
|
-
const createResponse = await fetch(createURL, {
|
|
433
|
-
method: "POST",
|
|
434
|
-
headers: this.getAuthorizedHeaders(),
|
|
435
|
-
body: JSON.stringify(createBody),
|
|
436
|
-
});
|
|
437
|
-
if (!createResponse.ok) {
|
|
438
|
-
const errorBody = await createResponse.json().catch(() => ({}));
|
|
439
|
-
throw createSimpleException({
|
|
440
|
-
code: createResponse.status,
|
|
441
|
-
message: errorBody.error?.message || createResponse.statusText,
|
|
442
|
-
type: "error",
|
|
443
|
-
source: "strapi-utils/client.ts",
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
const { data: created } = z
|
|
447
|
-
.object({ data: z.object({ id: z.number() }).loose() })
|
|
448
|
-
.parse(await createResponse.json());
|
|
449
|
-
currentParentId = created.id;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
return currentParentId;
|
|
453
|
-
}
|
|
454
392
|
/**
|
|
455
393
|
* Carica un file sulla Media Library di Strapi.
|
|
456
394
|
*
|
|
@@ -497,10 +435,6 @@ class Client {
|
|
|
497
435
|
blob = file;
|
|
498
436
|
fileName = options.filename ?? ("name" in file ? file.name : "upload");
|
|
499
437
|
}
|
|
500
|
-
let folderId;
|
|
501
|
-
if (options.path) {
|
|
502
|
-
folderId = await this.getOrCreateFolder(options.path);
|
|
503
|
-
}
|
|
504
438
|
const formData = new FormData();
|
|
505
439
|
formData.append("files", blob, fileName);
|
|
506
440
|
if (ref !== undefined)
|
|
@@ -509,9 +443,6 @@ class Client {
|
|
|
509
443
|
formData.append("refId", String(refId));
|
|
510
444
|
if (field !== undefined)
|
|
511
445
|
formData.append("field", field);
|
|
512
|
-
if (folderId !== undefined) {
|
|
513
|
-
formData.append("fileInfo", JSON.stringify({ folder: folderId }));
|
|
514
|
-
}
|
|
515
446
|
const requestURL = Client.getRequestURL({
|
|
516
447
|
origin: this.origin,
|
|
517
448
|
pathname: join(this.pathname, "upload"),
|