Skip to content

Commit

Permalink
filter videos by status
Browse files Browse the repository at this point in the history
  • Loading branch information
idoubi committed Feb 24, 2024
1 parent b935889 commit aafff58
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Sora AI Video Generator

> This project is a template for AI Video generating, it's not really work with your prompt until Sora API is available. All the videos show on Sora.FM are generated by OpenAI.
## Live Demo

[https://sora.fm](https://sora.fm)
Expand Down
3 changes: 2 additions & 1 deletion data/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ CREATE TABLE videos (
user_nickname VARCHAR(50),
user_avatar_url VARCHAR(255),
created_at timestamptz,
uuid UUID UNIQUE NOT NULL
uuid UUID UNIQUE NOT NULL,
status INT
);
12 changes: 7 additions & 5 deletions models/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export async function insertVideo(video: Video) {
const db = getDb();
const res = await db.query(
`INSERT INTO videos
(user_uuid, video_description, video_url, cover_url, post_url, user_nickname, user_avatar_url, created_at, uuid)
(user_uuid, video_description, video_url, cover_url, post_url, user_nickname, user_avatar_url, created_at, uuid, status)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9)
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
`,
[
video.user_uuid,
Expand All @@ -21,6 +21,7 @@ export async function insertVideo(video: Video) {
video.user_avatar_url,
video.created_at,
video.uuid,
video.status,
]
);

Expand Down Expand Up @@ -61,7 +62,7 @@ export async function findVideoByUuid(
): Promise<Video | undefined> {
const db = getDb();
const res = await db.query(
`select w.*, u.uuid as user_uuid, u.email as user_email, u.nickname as user_name, u.avatar_url as user_avatar from videos as w left join users as u on w.user_uuid = u.uuid::VARCHAR where w.uuid = $1`,
`select w.*, u.uuid as user_uuid, u.email as user_email, u.nickname as user_name, u.avatar_url as user_avatar from videos as w left join users as u on w.user_uuid = u.uuid::VARCHAR where w.uuid = $1 and w.status = 1`,
[uuid]
);
if (res.rowCount === 0) {
Expand All @@ -87,7 +88,7 @@ export async function getRandVideos(

const db = getDb();
const res = await db.query(
`select w.*, u.uuid as user_uuid, u.email as user_email, u.nickname as user_name, u.avatar_url as user_avatar from videos as w left join users as u on w.user_uuid = u.uuid::VARCHAR order by random() limit $1 offset $2`,
`select w.*, u.uuid as user_uuid, u.email as user_email, u.nickname as user_name, u.avatar_url as user_avatar from videos as w left join users as u on w.user_uuid = u.uuid::VARCHAR where w.status = 1 order by random() limit $1 offset $2`,
[limit, offset]
);

Expand All @@ -111,7 +112,7 @@ export async function getVideos(page: number, limit: number): Promise<Video[]> {

const db = getDb();
const res = await db.query(
`select w.*, u.uuid as user_uuid, u.email as user_email, u.nickname as user_name, u.avatar_url as user_avatar from videos as w left join users as u on w.user_uuid = u.uuid::VARCHAR order by w.created_at desc limit $1 offset $2`,
`select w.*, u.uuid as user_uuid, u.email as user_email, u.nickname as user_name, u.avatar_url as user_avatar from videos as w left join users as u on w.user_uuid = u.uuid::VARCHAR where w.status = 1 order by w.created_at desc limit $1 offset $2`,
[limit, offset]
);
if (res.rowCount === 0) {
Expand Down Expand Up @@ -153,6 +154,7 @@ export function formatVideo(row: QueryResultRow): Video | undefined {
user_avatar_url: row.user_avatar_url,
created_at: row.created_at,
uuid: row.uuid,
status: row.status,
};

return video;
Expand Down
1 change: 1 addition & 0 deletions types/video.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface Video {
user_avatar_url?: string;
created_at: string;
uuid: string;
status?: number;
}

0 comments on commit aafff58

Please sign in to comment.