mirror of https://github.com/renzynx/bliss.git
fix for regular audio without album cover
This commit is contained in:
parent
c5ba7ae1df
commit
a844b06f9e
|
@ -73,17 +73,14 @@ export class UsersController {
|
|||
@Query("sort") sort?: string,
|
||||
@Query("search") search?: string
|
||||
) {
|
||||
return this.usersService.getUserFiles(
|
||||
(req.session as CustomSession).userId,
|
||||
{
|
||||
skip: +skip,
|
||||
// @ts-ignore
|
||||
take: take === "all" ? "all" : +take,
|
||||
currentPage: +currentPage,
|
||||
sort,
|
||||
search,
|
||||
}
|
||||
);
|
||||
return this.usersService.getUserFiles(req, {
|
||||
skip: +skip,
|
||||
// @ts-ignore
|
||||
take: take === "all" ? "all" : +take,
|
||||
currentPage: +currentPage,
|
||||
sort,
|
||||
search,
|
||||
});
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
|
|
|
@ -35,6 +35,7 @@ import { join } from "path";
|
|||
import { readFile, unlink } from "fs/promises";
|
||||
import { EmbedSettingDTO } from "./dto/EmbedSettingsDTO";
|
||||
import cuid from "cuid";
|
||||
import { existsSync } from "fs";
|
||||
|
||||
@Injectable()
|
||||
export class UsersService implements IUserService {
|
||||
|
@ -391,7 +392,7 @@ export class UsersService implements IUserService {
|
|||
}
|
||||
|
||||
async getUserFiles(
|
||||
id: string,
|
||||
req: Request,
|
||||
{
|
||||
skip,
|
||||
take,
|
||||
|
@ -406,7 +407,10 @@ export class UsersService implements IUserService {
|
|||
search?: string;
|
||||
}
|
||||
) {
|
||||
const user = await this.findUser(id, { byId: true });
|
||||
const id = (req.session as CustomSession).userId;
|
||||
const user = await this.findUser(id, {
|
||||
byId: true,
|
||||
});
|
||||
if (!user) {
|
||||
throw new UnauthorizedException("not authorized");
|
||||
}
|
||||
|
@ -475,10 +479,24 @@ export class UsersService implements IUserService {
|
|||
case "newest":
|
||||
take !== total && files.reverse();
|
||||
}
|
||||
return files.map((file) => ({
|
||||
...file,
|
||||
size: formatBytes(file.size),
|
||||
}));
|
||||
return files.map((file) => {
|
||||
let albumCover = null;
|
||||
|
||||
if (
|
||||
file.mimetype.includes("audio") &&
|
||||
existsSync(join(uploadDir, `${file.slug}.jpg`))
|
||||
) {
|
||||
const protocol = req.headers["x-forwarded-proto"] || "http";
|
||||
const host = req.headers.host;
|
||||
albumCover = `${protocol}://${host}/${file.slug}.jpg`;
|
||||
}
|
||||
|
||||
return {
|
||||
...file,
|
||||
size: formatBytes(file.size),
|
||||
albumCover,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
|
@ -123,12 +123,14 @@ const PreviewCard: FC<{
|
|||
</video>
|
||||
) : file.mimetype.includes('audio') ? (
|
||||
<Stack align="center">
|
||||
<Image
|
||||
width={300}
|
||||
height={300}
|
||||
src={`${API_URL}/${file.slug}.jpg`}
|
||||
alt="Album Cover"
|
||||
/>
|
||||
{file.albumCover && (
|
||||
<Image
|
||||
width={300}
|
||||
height={300}
|
||||
src={`${API_URL}/${file.slug}.jpg`}
|
||||
alt="Album Cover"
|
||||
/>
|
||||
)}
|
||||
<audio controls loop preload="metadata">
|
||||
<source src={fileURL} />
|
||||
</audio>
|
||||
|
|
|
@ -99,6 +99,7 @@ export interface IFile {
|
|||
size: number;
|
||||
userId: string;
|
||||
createdAt: Date;
|
||||
albumCover: string | null;
|
||||
}
|
||||
|
||||
export interface FileResponse {
|
||||
|
|
Loading…
Reference in New Issue