returning queue on blog endpoint
This commit is contained in:
parent
3bf83041ff
commit
fca37022d7
@ -1,4 +1,4 @@
|
||||
import { and, desc, eq, or, sql } from "drizzle-orm";
|
||||
import { and, desc, eq, not, or, sql } from "drizzle-orm";
|
||||
import { db } from "../db/index.js";
|
||||
import { authMiddlewareFn } from "../modules/middleware.js";
|
||||
import { articles, articles as articlesTable, signups as signupsTable, sites, users } from "../db/schemas.js";
|
||||
@ -64,7 +64,7 @@ export const blogRoutes = (fastify, _, done) => {
|
||||
}
|
||||
|
||||
clause = eq(articlesTable.site_id, site.id);
|
||||
if (mine == false) {
|
||||
if (!mine) {
|
||||
clause = and(eq(articlesTable.site_id, site.id), eq(articlesTable.is_public, true));
|
||||
}
|
||||
// const access_token = await getAccessToken(fastify, request);
|
||||
@ -77,17 +77,31 @@ export const blogRoutes = (fastify, _, done) => {
|
||||
views: articlesTable.views,
|
||||
is_public: articlesTable.is_public,
|
||||
created_at: articlesTable.created_at,
|
||||
}).from(articlesTable).where(clause).limit(10).offset(request.query.offset || 0).orderBy(desc(articlesTable.created_at));
|
||||
}).from(articlesTable).where(and(eq(articlesTable.status, "done"), clause)).limit(10).offset(request.query.offset || 0).orderBy(desc(articlesTable.created_at));
|
||||
|
||||
const [{ total }] = await db.select({
|
||||
total: sql`COUNT(*)`
|
||||
}).from(articlesTable).where(clause);
|
||||
|
||||
let queue = [];
|
||||
if (mine) {
|
||||
queue = await db.select({
|
||||
id: articlesTable.id,
|
||||
title: articlesTable.title,
|
||||
seo_slug: articlesTable.seo_slug,
|
||||
views: articlesTable.views,
|
||||
is_public: articlesTable.is_public,
|
||||
created_at: articlesTable.created_at,
|
||||
status: articlesTable.status
|
||||
}).where(and(eq(articlesTable.site_id, site.id), not(articlesTable.status, "done")));
|
||||
}
|
||||
|
||||
response.send({
|
||||
success: true,
|
||||
articles: results,
|
||||
total_articles: total,
|
||||
site,
|
||||
queue
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
@ -6,7 +6,6 @@ import ytdl from 'ytdl-core';
|
||||
import { getWhisperCaptions } from './ai.js';
|
||||
const service = google.youtube("v3");
|
||||
|
||||
|
||||
export async function getVideoById(access_token, video_id) {
|
||||
const video = await service.videos.list({
|
||||
access_token,
|
||||
|
Loading…
Reference in New Issue
Block a user