You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: models/video.ts
+47-37
Original file line number
Diff line number
Diff line change
@@ -78,53 +78,63 @@ export async function getRandomVideos(
78
78
page: number,
79
79
limit: number
80
80
): Promise<Video[]>{
81
-
if(page<=0){
82
-
page=1;
83
-
}
84
-
if(limit<=0){
85
-
limit=50;
86
-
}
87
-
constoffset=(page-1)*limit;
88
-
89
-
constdb=getDb();
90
-
constres=awaitdb.query(
91
-
`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`,
92
-
[limit,offset]
93
-
);
94
-
95
-
if(res.rowCount===0){
81
+
try{
82
+
if(page<=0){
83
+
page=1;
84
+
}
85
+
if(limit<=0){
86
+
limit=50;
87
+
}
88
+
constoffset=(page-1)*limit;
89
+
90
+
constdb=getDb();
91
+
constres=awaitdb.query(
92
+
`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`,
93
+
[limit,offset]
94
+
);
95
+
96
+
if(res.rowCount===0){
97
+
return[];
98
+
}
99
+
100
+
constvideos=getVideosFromSqlResult(res);
101
+
102
+
returnvideos;
103
+
}catch(error){
104
+
console.log("get random videos error",error);
96
105
return[];
97
106
}
98
-
99
-
constvideos=getVideosFromSqlResult(res);
100
-
101
-
returnvideos;
102
107
}
103
108
104
109
exportasyncfunctiongetLatestVideos(
105
110
page: number,
106
111
limit: number
107
112
): Promise<Video[]>{
108
-
if(page<1){
109
-
page=1;
110
-
}
111
-
if(limit<=0){
112
-
limit=50;
113
-
}
114
-
constoffset=(page-1)*limit;
115
-
116
-
constdb=getDb();
117
-
constres=awaitdb.query(
118
-
`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`,
119
-
[limit,offset]
120
-
);
121
-
if(res.rowCount===0){
113
+
try{
114
+
if(page<1){
115
+
page=1;
116
+
}
117
+
if(limit<=0){
118
+
limit=50;
119
+
}
120
+
constoffset=(page-1)*limit;
121
+
122
+
constdb=getDb();
123
+
constres=awaitdb.query(
124
+
`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`,
0 commit comments