v3: added emoji picker, various bug and layout fixes
This commit is contained in:
@@ -17,8 +17,8 @@ import {
|
||||
notifyUserFollowersNewDump,
|
||||
} from "./notification-service.ts";
|
||||
import { makeSlug, UUID_RE } from "../lib/slugify.ts";
|
||||
import { DUMPS_DIR } from "../utils/upload.ts";
|
||||
|
||||
const UPLOADS_DIR = "api/uploads";
|
||||
const MAX_FILE_SIZE = 50 * 1024 * 1024; // 50 MB
|
||||
|
||||
const ALLOWED_MIME_PREFIXES = ["text/", "image/", "video/", "audio/"];
|
||||
@@ -138,11 +138,11 @@ export async function createFileDump(
|
||||
const createdAt = new Date();
|
||||
const slug = makeSlug(file.name, dumpId);
|
||||
|
||||
await Deno.mkdir(UPLOADS_DIR, { recursive: true });
|
||||
await Deno.mkdir(DUMPS_DIR, { recursive: true });
|
||||
const data = new Uint8Array(await file.arrayBuffer());
|
||||
|
||||
try {
|
||||
await Deno.writeFile(`${UPLOADS_DIR}/${dumpId}`, data);
|
||||
await Deno.writeFile(`${DUMPS_DIR}/${dumpId}`, data);
|
||||
|
||||
db.prepare(
|
||||
`INSERT INTO dumps (id, kind, title, slug, comment, user_id, created_at, file_name, file_mime, file_size, is_private)
|
||||
@@ -162,7 +162,7 @@ export async function createFileDump(
|
||||
);
|
||||
} catch (err) {
|
||||
// Roll back the file if DB insert fails
|
||||
await Deno.remove(`${UPLOADS_DIR}/${dumpId}`).catch(() => {});
|
||||
await Deno.remove(`${DUMPS_DIR}/${dumpId}`).catch(() => {});
|
||||
throw err;
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ export async function replaceFileDump(
|
||||
}
|
||||
|
||||
const data = new Uint8Array(await file.arrayBuffer());
|
||||
await Deno.writeFile(`${UPLOADS_DIR}/${dumpId}`, data);
|
||||
await Deno.writeFile(`${DUMPS_DIR}/${dumpId}`, data);
|
||||
|
||||
const now = new Date();
|
||||
const newSlug = makeSlug(file.name, dumpId);
|
||||
@@ -513,7 +513,7 @@ export async function deleteDump(dumpId: string): Promise<void> {
|
||||
}
|
||||
|
||||
if (dump.kind === "file") {
|
||||
await Deno.remove(`${UPLOADS_DIR}/${dumpId}`).catch(() => {});
|
||||
await Deno.remove(`${DUMPS_DIR}/${dumpId}`).catch(() => {});
|
||||
}
|
||||
|
||||
broadcastDumpDeleted(dumpId);
|
||||
|
||||
@@ -356,13 +356,13 @@ export function getPlaylistMembershipsForDump(
|
||||
});
|
||||
}
|
||||
|
||||
export function getPlaylistImageMime(playlistId: string): string | undefined {
|
||||
const row = db.prepare(`SELECT image_mime FROM playlists WHERE id = ?;`).get(
|
||||
playlistId,
|
||||
) as
|
||||
| { image_mime: string | null }
|
||||
| undefined;
|
||||
return row?.image_mime ?? undefined;
|
||||
export function getPlaylistImageInfo(
|
||||
idOrSlug: string,
|
||||
): { id: string; imageMime: string } | undefined {
|
||||
const playlist = getPlaylistById(idOrSlug);
|
||||
return playlist.imageMime
|
||||
? { id: playlist.id, imageMime: playlist.imageMime }
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function getCurrentDumpIds(playlistId: string): string[] {
|
||||
|
||||
@@ -10,7 +10,7 @@ import { db, isUserRow, userApiToRow, userRowToApi } from "../model/db.ts";
|
||||
import { hashPassword } from "../lib/jwt.ts";
|
||||
|
||||
const USER_SELECT =
|
||||
`SELECT u.id, u.username, u.password_hash, u.is_admin, u.created_at, u.avatar_mime, u.invited_by,
|
||||
`SELECT u.id, u.username, u.password_hash, u.is_admin, u.created_at, u.updated_at, u.avatar_mime, u.invited_by,
|
||||
i.username as invited_by_username
|
||||
FROM users u
|
||||
LEFT JOIN users i ON i.id = u.invited_by`;
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface WsClient {
|
||||
userId?: string;
|
||||
username?: string;
|
||||
avatarMime?: string;
|
||||
avatarVersion?: number;
|
||||
}
|
||||
|
||||
const clients = new Set<WsClient>();
|
||||
@@ -23,9 +24,11 @@ export function unregister(client: WsClient): void {
|
||||
}
|
||||
|
||||
export function updateClientAvatar(userId: string, avatarMime: string): void {
|
||||
const version = Date.now();
|
||||
for (const client of clients) {
|
||||
if (client.userId === userId) {
|
||||
client.avatarMime = avatarMime;
|
||||
client.avatarVersion = version;
|
||||
}
|
||||
}
|
||||
broadcastPresence();
|
||||
@@ -39,6 +42,7 @@ export function getOnlineUsers(): OnlineUser[] {
|
||||
userId: client.userId,
|
||||
username: client.username!,
|
||||
hasAvatar: !!client.avatarMime,
|
||||
avatarVersion: client.avatarVersion,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user