mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
feat(api): ✨ Add ability to set URL as avatar or banner
This commit is contained in:
parent
41341cf252
commit
6f67881d96
|
|
@ -69,17 +69,33 @@ export const schemas = {
|
||||||
)
|
)
|
||||||
.optional(),
|
.optional(),
|
||||||
avatar: z
|
avatar: z
|
||||||
.instanceof(File)
|
.string()
|
||||||
.refine(
|
.trim()
|
||||||
(v) => v.size <= config.validation.max_avatar_size,
|
.min(1)
|
||||||
`Avatar must be less than ${config.validation.max_avatar_size} bytes`,
|
.max(2000)
|
||||||
|
.url()
|
||||||
|
.or(
|
||||||
|
z
|
||||||
|
.instanceof(File)
|
||||||
|
.refine(
|
||||||
|
(v) => v.size <= config.validation.max_avatar_size,
|
||||||
|
`Avatar must be less than ${config.validation.max_avatar_size} bytes`,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.optional(),
|
.optional(),
|
||||||
header: z
|
header: z
|
||||||
.instanceof(File)
|
.string()
|
||||||
.refine(
|
.trim()
|
||||||
(v) => v.size <= config.validation.max_header_size,
|
.min(1)
|
||||||
`Header must be less than ${config.validation.max_header_size} bytes`,
|
.max(2000)
|
||||||
|
.url()
|
||||||
|
.or(
|
||||||
|
z
|
||||||
|
.instanceof(File)
|
||||||
|
.refine(
|
||||||
|
(v) => v.size <= config.validation.max_header_size,
|
||||||
|
`Header must be less than ${config.validation.max_header_size} bytes`,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.optional(),
|
.optional(),
|
||||||
locked: z
|
locked: z
|
||||||
|
|
@ -250,15 +266,23 @@ export default apiRoute((app) =>
|
||||||
}
|
}
|
||||||
|
|
||||||
if (avatar) {
|
if (avatar) {
|
||||||
const { path } = await mediaManager.addFile(avatar);
|
if (avatar instanceof File) {
|
||||||
|
const { path } = await mediaManager.addFile(avatar);
|
||||||
|
|
||||||
self.avatar = Attachment.getUrl(path);
|
self.avatar = Attachment.getUrl(path);
|
||||||
|
} else {
|
||||||
|
self.avatar = avatar;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header) {
|
if (header) {
|
||||||
const { path } = await mediaManager.addFile(header);
|
if (header instanceof File) {
|
||||||
|
const { path } = await mediaManager.addFile(header);
|
||||||
|
|
||||||
self.header = Attachment.getUrl(path);
|
self.header = Attachment.getUrl(path);
|
||||||
|
} else {
|
||||||
|
self.header = header;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (locked) {
|
if (locked) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue