fix(restore): accept originals paths in group photos
- validate group_photos.photo_original_path with the same tolerant helper as entries, so /uploads/.originals/<file> no longer fails restore with "Invalid upload path" - accept legacy flat values in both photo_original_path columns - preserve users.avatar in normalizeRestoreData and the restore INSERT - add selftests for originals paths and avatars
This commit is contained in:
+3
-8
@@ -151,12 +151,6 @@ function optUploadPath(v, max) {
|
||||
|
||||
const ORIGINALS_PATH_RE = /^\/uploads\/\.originals\/[\w.,()-]+$/;
|
||||
|
||||
function optOriginalsPath(v, max) {
|
||||
if (v === null || v === undefined) return null;
|
||||
if (typeof v !== 'string' || v.length > max || !ORIGINALS_PATH_RE.test(v)) throw new Error('Invalid originals path');
|
||||
return v;
|
||||
}
|
||||
|
||||
function reqPhotoRefPath(v, max) {
|
||||
if (typeof v !== 'string' || v.length > max) throw new Error('Invalid photo path');
|
||||
if (isSafeUploadPath(v) || ORIGINALS_PATH_RE.test(v)) return v;
|
||||
@@ -333,7 +327,7 @@ function normalizeRestoreData(data) {
|
||||
ai_checked_at: optTs(x.ai_checked_at),
|
||||
ai_error: optAiText(x.ai_error, 500),
|
||||
photo_path: optUploadPath(x.photo_path, 255),
|
||||
photo_original_path: optOriginalsPath(x.photo_original_path, 255),
|
||||
photo_original_path: optPhotoRefPath(x.photo_original_path, 255),
|
||||
deleted_at: optTs(x.deleted_at),
|
||||
purge_at: optTs(x.purge_at),
|
||||
created_at: optTs(x.created_at),
|
||||
@@ -359,6 +353,7 @@ function normalizeRestoreData(data) {
|
||||
username: reqStr(x.username, 100),
|
||||
password_hash: reqStr(x.password_hash, 255),
|
||||
name: optStr(x.name, 150),
|
||||
avatar: optUploadPath(x.avatar, 255),
|
||||
role: (x.role === 'admin' || x.role === 'tutor') ? x.role : 'tutor',
|
||||
is_active: !!x.is_active,
|
||||
created_at: optTs(x.created_at),
|
||||
@@ -397,7 +392,7 @@ function normalizeRestoreData(data) {
|
||||
id: reqInt(x.id),
|
||||
group_id: reqInt(x.group_id),
|
||||
photo_path: reqUploadPath(x.photo_path, 255),
|
||||
photo_original_path: optUploadPath(x.photo_original_path, 255),
|
||||
photo_original_path: optPhotoRefPath(x.photo_original_path, 255),
|
||||
caption: optStr(x.caption, 10000),
|
||||
taken_at: optDate(x.taken_at),
|
||||
sort_order: optInt(x.sort_order, -2147483648, 2147483647),
|
||||
|
||||
Reference in New Issue
Block a user