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("sort") sort?: string,
|
||||||
@Query("search") search?: string
|
@Query("search") search?: string
|
||||||
) {
|
) {
|
||||||
return this.usersService.getUserFiles(
|
return this.usersService.getUserFiles(req, {
|
||||||
(req.session as CustomSession).userId,
|
skip: +skip,
|
||||||
{
|
// @ts-ignore
|
||||||
skip: +skip,
|
take: take === "all" ? "all" : +take,
|
||||||
// @ts-ignore
|
currentPage: +currentPage,
|
||||||
take: take === "all" ? "all" : +take,
|
sort,
|
||||||
currentPage: +currentPage,
|
search,
|
||||||
sort,
|
});
|
||||||
search,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
|
|
|
@ -35,6 +35,7 @@ import { join } from "path";
|
||||||
import { readFile, unlink } from "fs/promises";
|
import { readFile, unlink } from "fs/promises";
|
||||||
import { EmbedSettingDTO } from "./dto/EmbedSettingsDTO";
|
import { EmbedSettingDTO } from "./dto/EmbedSettingsDTO";
|
||||||
import cuid from "cuid";
|
import cuid from "cuid";
|
||||||
|
import { existsSync } from "fs";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService implements IUserService {
|
export class UsersService implements IUserService {
|
||||||
|
@ -391,7 +392,7 @@ export class UsersService implements IUserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUserFiles(
|
async getUserFiles(
|
||||||
id: string,
|
req: Request,
|
||||||
{
|
{
|
||||||
skip,
|
skip,
|
||||||
take,
|
take,
|
||||||
|
@ -406,7 +407,10 @@ export class UsersService implements IUserService {
|
||||||
search?: string;
|
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) {
|
if (!user) {
|
||||||
throw new UnauthorizedException("not authorized");
|
throw new UnauthorizedException("not authorized");
|
||||||
}
|
}
|
||||||
|
@ -475,10 +479,24 @@ export class UsersService implements IUserService {
|
||||||
case "newest":
|
case "newest":
|
||||||
take !== total && files.reverse();
|
take !== total && files.reverse();
|
||||||
}
|
}
|
||||||
return files.map((file) => ({
|
return files.map((file) => {
|
||||||
...file,
|
let albumCover = null;
|
||||||
size: formatBytes(file.size),
|
|
||||||
}));
|
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 {
|
return {
|
||||||
|
|
|
@ -123,12 +123,14 @@ const PreviewCard: FC<{
|
||||||
</video>
|
</video>
|
||||||
) : file.mimetype.includes('audio') ? (
|
) : file.mimetype.includes('audio') ? (
|
||||||
<Stack align="center">
|
<Stack align="center">
|
||||||
<Image
|
{file.albumCover && (
|
||||||
width={300}
|
<Image
|
||||||
height={300}
|
width={300}
|
||||||
src={`${API_URL}/${file.slug}.jpg`}
|
height={300}
|
||||||
alt="Album Cover"
|
src={`${API_URL}/${file.slug}.jpg`}
|
||||||
/>
|
alt="Album Cover"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<audio controls loop preload="metadata">
|
<audio controls loop preload="metadata">
|
||||||
<source src={fileURL} />
|
<source src={fileURL} />
|
||||||
</audio>
|
</audio>
|
||||||
|
|
|
@ -99,6 +99,7 @@ export interface IFile {
|
||||||
size: number;
|
size: number;
|
||||||
userId: string;
|
userId: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
albumCover: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FileResponse {
|
export interface FileResponse {
|
||||||
|
|
Loading…
Reference in New Issue