@sequent-org/moodboard 1.4.7 → 1.4.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequent-org/moodboard",
3
- "version": "1.4.7",
3
+ "version": "1.4.8",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
@@ -1,8 +1,26 @@
1
1
  export function isV2ImageDownloadUrl(url) {
2
- return typeof url === 'string' && /^\/api\/v2\/images\/[^/]+\/download$/i.test(url.trim());
2
+ if (typeof url !== 'string') return false;
3
+ const raw = url.trim();
4
+ if (!raw) return false;
5
+ if (/^\/api\/v2\/images\/[^/]+\/download$/i.test(raw)) return true;
6
+ try {
7
+ const parsed = new URL(raw);
8
+ return /^\/api\/v2\/images\/[^/]+\/download$/i.test(parsed.pathname);
9
+ } catch (_) {
10
+ return false;
11
+ }
3
12
  }
4
13
 
5
14
  export function isV2FileDownloadUrl(url) {
6
- return typeof url === 'string' && /^\/api\/v2\/files\/[^/]+\/download$/i.test(url.trim());
15
+ if (typeof url !== 'string') return false;
16
+ const raw = url.trim();
17
+ if (!raw) return false;
18
+ if (/^\/api\/v2\/files\/[^/]+\/download$/i.test(raw)) return true;
19
+ try {
20
+ const parsed = new URL(raw);
21
+ return /^\/api\/v2\/files\/[^/]+\/download$/i.test(parsed.pathname);
22
+ } catch (_) {
23
+ return false;
24
+ }
7
25
  }
8
26
 
@@ -102,6 +102,9 @@ export class FileUploadService {
102
102
  if (!isV2FileDownloadUrl(serverUrl)) {
103
103
  throw new Error('Некорректный URL файла от сервера. Ожидается /api/v2/files/{fileId}/download');
104
104
  }
105
+ if (!this._matchesFileIdInUrl(serverUrl, fileId)) {
106
+ throw new Error('fileId не совпадает с URL файла от сервера.');
107
+ }
105
108
 
106
109
  return {
107
110
  id: fileId, // Используем fileId как основное поле, id для обратной совместимости
@@ -118,6 +121,23 @@ export class FileUploadService {
118
121
  }
119
122
  }
120
123
 
124
+ _matchesFileIdInUrl(url, fileId) {
125
+ const id = typeof fileId === 'string' ? fileId.trim() : '';
126
+ if (!id || typeof url !== 'string') return false;
127
+ const raw = url.trim();
128
+ const relativeMatch = raw.match(/^\/api\/v2\/files\/([^/]+)\/download$/i);
129
+ if (relativeMatch) {
130
+ return decodeURIComponent(relativeMatch[1]) === id;
131
+ }
132
+ try {
133
+ const parsed = new URL(raw);
134
+ const absoluteMatch = parsed.pathname.match(/^\/api\/v2\/files\/([^/]+)\/download$/i);
135
+ return !!absoluteMatch && decodeURIComponent(absoluteMatch[1]) === id;
136
+ } catch (_) {
137
+ return false;
138
+ }
139
+ }
140
+
121
141
  /**
122
142
  * Обновляет метаданные файла на сервере
123
143
  * @param {string} fileId - ID файла
@@ -107,6 +107,9 @@ export class ImageUploadService {
107
107
  if (!isV2ImageDownloadUrl(serverUrl)) {
108
108
  throw new Error('Некорректный URL изображения от сервера. Ожидается /api/v2/images/{imageId}/download');
109
109
  }
110
+ if (!this._matchesImageIdInUrl(serverUrl, imageId)) {
111
+ throw new Error('imageId не совпадает с URL изображения от сервера.');
112
+ }
110
113
 
111
114
  return {
112
115
  id: imageId, // Используем imageId как основное поле, id для обратной совместимости
@@ -124,6 +127,23 @@ export class ImageUploadService {
124
127
  }
125
128
  }
126
129
 
130
+ _matchesImageIdInUrl(url, imageId) {
131
+ const id = typeof imageId === 'string' ? imageId.trim() : '';
132
+ if (!id || typeof url !== 'string') return false;
133
+ const raw = url.trim();
134
+ const relativeMatch = raw.match(/^\/api\/v2\/images\/([^/]+)\/download$/i);
135
+ if (relativeMatch) {
136
+ return decodeURIComponent(relativeMatch[1]) === id;
137
+ }
138
+ try {
139
+ const parsed = new URL(raw);
140
+ const absoluteMatch = parsed.pathname.match(/^\/api\/v2\/images\/([^/]+)\/download$/i);
141
+ return !!absoluteMatch && decodeURIComponent(absoluteMatch[1]) === id;
142
+ } catch (_) {
143
+ return false;
144
+ }
145
+ }
146
+
127
147
  /**
128
148
  * Загружает изображение из base64 DataURL
129
149
  * @param {string} dataUrl - base64 DataURL