Skip to content

Commit

Permalink
fix: more export validation
Browse files Browse the repository at this point in the history
  • Loading branch information
diced committed Dec 16, 2024
1 parent 57e9790 commit 4d472a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/lib/import/version3/validateExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const export3Schema = z.object({
z.object({
username: z.string(),
password: z.string(),
avatar: z.string(),
avatar: z.string().optional().nullable(),
administrator: z.boolean(),
super_administrator: z.boolean(),
embed: z.object({
Expand All @@ -206,12 +206,12 @@ export const export3Schema = z.object({
files: z.record(
z.object({
name: z.string(),
original_name: z.string().nullable(),
original_name: z.string().optional().nullable(),
type: z.string(),
size: z.union([z.number(), z.bigint()]),
user: z.string().nullable(),
user: z.string().optional().nullable(),
thumbnail: z.string().optional().nullable(),
max_views: z.number().nullable(),
max_views: z.number().optional().nullable(),
views: z.number(),
expires_at: z.string().optional().nullable(),
created_at: z.string(),
Expand All @@ -232,7 +232,7 @@ export const export3Schema = z.object({
name: z.string(),
public: z.boolean(),
created_at: z.string(),
user: z.string(),
user: z.string().optional().nullable(),
files: z.array(z.string()),
}),
),
Expand All @@ -243,19 +243,19 @@ export const export3Schema = z.object({
vanity: z.string().optional().nullable(),
code: z.string(),
created_at: z.string(),
max_views: z.number(),
max_views: z.number().optional().nullable(),
views: z.number(),
user: z.string(),
user: z.string().optional().nullable(),
}),
),

invites: z.record(
z.object({
code: z.string(),
expites_at: z.string().optional().nullable(),
expires_at: z.string().optional().nullable(),
created_at: z.string(),
used: z.boolean(),
created_by_user: z.string(),
created_by_user: z.string().optional().nullable(),
}),
),

Expand Down
6 changes: 3 additions & 3 deletions src/server/routes/api/server/import/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default fastifyPlugin(
const filesImportedToId: Record<string, string> = {};

for (const [id, file] of Object.entries(export3.files)) {
const user = usersImportedToId[file.user || ''];
const user = file.user ? usersImportedToId[file.user] : undefined;
if (!user) {
logger.warn('failed to find user for file, skipping', { file: id });

Expand Down Expand Up @@ -170,7 +170,7 @@ export default fastifyPlugin(
const foldersImportedToId: Record<string, string> = {};

for (const [id, folder] of Object.entries(export3.folders)) {
const user = usersImportedToId[folder.user];
const user = folder.user ? usersImportedToId[folder.user] : undefined;
if (!user) {
logger.warn('failed to find user for folder, skipping', { folder: id });

Expand Down Expand Up @@ -207,7 +207,7 @@ export default fastifyPlugin(
const urlsImportedToId: Record<string, string> = {};

for (const [id, url] of Object.entries(export3.urls)) {
const user = usersImportedToId[url.user];
const user = url.user ? usersImportedToId[url.user] : undefined;
if (!user) {
logger.warn('failed to find user for url, skipping', { url: id });

Expand Down

0 comments on commit 4d472a1

Please sign in to comment.