mirror of
https://github.com/ngthanhvu/kr-phim.git
synced 2026-08-10 15:07:46 +00:00
feat: add movie management API and database schema
- Implemented movie CRUD operations with endpoints for creating, retrieving, updating, and deleting movies. - Added pagination and filtering capabilities for movie retrieval. - Integrated Redis caching for improved performance on movie data retrieval. - Created database schema for movies with necessary fields and types. - Added migration files for initial movie table creation and subsequent updates. - Configured database connection using Drizzle ORM with MySQL. - Established Redis connection utility for caching.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { movies } from '../../database/schema'
|
||||
import { useRedis } from '../../utils/redis'
|
||||
|
||||
export default defineEventHandler(async () => {
|
||||
const db = useDb()
|
||||
|
||||
await db.delete(movies)
|
||||
|
||||
try {
|
||||
const redis = useRedis()
|
||||
const keys = await redis.keys('cinek:public:*')
|
||||
if (keys.length) await redis.del(...keys)
|
||||
} catch {}
|
||||
|
||||
return { success: true }
|
||||
})
|
||||
@@ -0,0 +1,47 @@
|
||||
import { movies } from '../../database/schema'
|
||||
import { desc, like, sql } from 'drizzle-orm'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const db = useDb()
|
||||
const query = getQuery(event)
|
||||
const page = Math.max(Number(query.page) || 1, 1)
|
||||
const limit = Math.min(Math.max(Number(query.limit) || 20, 1), 100)
|
||||
const offset = (page - 1) * limit
|
||||
const keyword = typeof query.keyword === 'string' ? query.keyword.trim() : ''
|
||||
const status = typeof query.status === 'string' ? query.status : ''
|
||||
|
||||
let whereClause = undefined
|
||||
if (keyword && status === 'active') {
|
||||
whereClause = sql`${like(movies.name, `%${keyword}%`)} AND ${movies.active} = true`
|
||||
} else if (keyword) {
|
||||
whereClause = like(movies.name, `%${keyword}%`)
|
||||
} else if (status === 'active') {
|
||||
whereClause = eq(movies.active, true)
|
||||
} else if (status === 'inactive') {
|
||||
whereClause = eq(movies.active, false)
|
||||
}
|
||||
|
||||
const [items, countResult] = await Promise.all([
|
||||
db
|
||||
.select()
|
||||
.from(movies)
|
||||
.where(whereClause)
|
||||
.orderBy(desc(movies.syncedAt))
|
||||
.limit(limit)
|
||||
.offset(offset),
|
||||
db
|
||||
.select({ count: sql<number>`count(*)` })
|
||||
.from(movies)
|
||||
.where(whereClause),
|
||||
])
|
||||
|
||||
const total = countResult[0]?.count ?? 0
|
||||
|
||||
return {
|
||||
items,
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
import { movies } from '../../../database/schema'
|
||||
import { eq } from 'drizzle-orm'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const db = useDb()
|
||||
const id = Number(getRouterParam(event, 'id'))
|
||||
|
||||
if (!id) {
|
||||
throw createError({ statusCode: 400, message: 'Thiếu ID phim' })
|
||||
}
|
||||
|
||||
const result = await db.select().from(movies).where(eq(movies.id, id)).limit(1)
|
||||
if (!result.length) {
|
||||
throw createError({ statusCode: 404, message: 'Không tìm thấy phim' })
|
||||
}
|
||||
|
||||
return result[0]
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
import { movies } from '../../../database/schema'
|
||||
import { eq } from 'drizzle-orm'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const db = useDb()
|
||||
const id = Number(getRouterParam(event, 'id'))
|
||||
const body = await readBody(event)
|
||||
|
||||
if (!id) {
|
||||
throw createError({ statusCode: 400, message: 'Thiếu ID phim' })
|
||||
}
|
||||
|
||||
const existing = await db.select().from(movies).where(eq(movies.id, id)).limit(1)
|
||||
if (!existing.length) {
|
||||
throw createError({ statusCode: 404, message: 'Không tìm thấy phim' })
|
||||
}
|
||||
|
||||
const updates: Record<string, any> = {}
|
||||
|
||||
if (typeof body.active === 'boolean') {
|
||||
updates.active = body.active
|
||||
}
|
||||
|
||||
if (!Object.keys(updates).length) {
|
||||
throw createError({ statusCode: 400, message: 'Không có dữ liệu cập nhật' })
|
||||
}
|
||||
|
||||
await db.update(movies).set(updates).where(eq(movies.id, id))
|
||||
|
||||
try {
|
||||
const redis = useRedis()
|
||||
const keys = await redis.keys('cinek:public:*')
|
||||
if (keys.length) {
|
||||
await redis.del(...keys)
|
||||
}
|
||||
} catch {}
|
||||
|
||||
return { success: true, id, ...updates }
|
||||
})
|
||||
@@ -0,0 +1,48 @@
|
||||
import { movies } from '../../../database/schema'
|
||||
import { eq } from 'drizzle-orm'
|
||||
import { useRedis } from '../../../utils/redis'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const db = useDb()
|
||||
const id = Number(getRouterParam(event, 'id'))
|
||||
const body = await readBody(event)
|
||||
|
||||
if (!id) {
|
||||
throw createError({ statusCode: 400, message: 'Thiếu ID phim' })
|
||||
}
|
||||
|
||||
const existing = await db.select().from(movies).where(eq(movies.id, id)).limit(1)
|
||||
if (!existing.length) {
|
||||
throw createError({ statusCode: 404, message: 'Không tìm thấy phim' })
|
||||
}
|
||||
|
||||
const updates: Record<string, any> = {}
|
||||
|
||||
for (const field of ['customPoster', 'customThumb', 'customContent'] as const) {
|
||||
if (field in body) {
|
||||
updates[field] = typeof body[field] === 'string' && body[field].trim()
|
||||
? body[field].trim()
|
||||
: null
|
||||
}
|
||||
}
|
||||
|
||||
if ('customEpisodes' in body) {
|
||||
updates.customEpisodes = Array.isArray(body.customEpisodes) && body.customEpisodes.length
|
||||
? body.customEpisodes.filter((ep: any) => ep.name?.trim())
|
||||
: null
|
||||
}
|
||||
|
||||
if (!Object.keys(updates).length) {
|
||||
throw createError({ statusCode: 400, message: 'Không có dữ liệu cập nhật' })
|
||||
}
|
||||
|
||||
await db.update(movies).set(updates).where(eq(movies.id, id))
|
||||
|
||||
try {
|
||||
const redis = useRedis()
|
||||
const keys = await redis.keys('cinek:public:*')
|
||||
if (keys.length) await redis.del(...keys)
|
||||
} catch {}
|
||||
|
||||
return { success: true, id }
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
import { movies } from '../../database/schema'
|
||||
import { sql } from 'drizzle-orm'
|
||||
|
||||
export default defineEventHandler(async () => {
|
||||
const db = useDb()
|
||||
|
||||
const [stats] = await db.select({
|
||||
total: sql<number>`count(*)`,
|
||||
active: sql<number>`SUM(CASE WHEN ${movies.active} = true THEN 1 ELSE 0 END)`,
|
||||
inactive: sql<number>`SUM(CASE WHEN ${movies.active} = false THEN 1 ELSE 0 END)`,
|
||||
}).from(movies)
|
||||
|
||||
return {
|
||||
total: stats?.total ?? 0,
|
||||
active: stats?.active ?? 0,
|
||||
inactive: stats?.inactive ?? 0,
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,104 @@
|
||||
import { movies } from '../../database/schema'
|
||||
import { eq, and } from 'drizzle-orm'
|
||||
import { getOphimKoreanMovies, getNguoncKoreanMovies, getKkphimKoreanMovies } from '../../utils/movies'
|
||||
|
||||
const SYNC_PAGES = 10
|
||||
const ALL_SOURCES = ['ophim', 'nguonc', 'kkphim'] as const
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const db = useDb()
|
||||
const body = await readBody(event).catch(() => ({})) || {}
|
||||
const requestedSources = Array.isArray(body.sources) ? body.sources : ALL_SOURCES
|
||||
const sources = requestedSources.filter((s: string) => ALL_SOURCES.includes(s as any))
|
||||
|
||||
if (!sources.length) {
|
||||
throw createError({ statusCode: 400, message: 'Nguồn không hợp lệ' })
|
||||
}
|
||||
|
||||
const allMovies: any[] = []
|
||||
const fetchers: Record<string, (page: number) => Promise<any>> = {
|
||||
ophim: getOphimKoreanMovies,
|
||||
nguonc: getNguoncKoreanMovies,
|
||||
kkphim: getKkphimKoreanMovies,
|
||||
}
|
||||
|
||||
for (const sourceName of sources) {
|
||||
const fetcher = fetchers[sourceName]
|
||||
if (!fetcher) continue
|
||||
for (let page = 1; page <= SYNC_PAGES; page++) {
|
||||
try {
|
||||
const result = await fetcher(page)
|
||||
for (const movie of result.items) {
|
||||
allMovies.push({ ...movie, source: sourceName })
|
||||
}
|
||||
if (!result.items.length) break
|
||||
} catch {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let created = 0
|
||||
let updated = 0
|
||||
|
||||
for (const movie of allMovies) {
|
||||
const existing = await db
|
||||
.select()
|
||||
.from(movies)
|
||||
.where(and(eq(movies.source, movie.source), eq(movies.slug, movie.slug)))
|
||||
.limit(1)
|
||||
|
||||
if (existing.length) {
|
||||
await db
|
||||
.update(movies)
|
||||
.set({
|
||||
name: movie.name,
|
||||
originName: movie.originName || null,
|
||||
thumb: movie.thumb || null,
|
||||
poster: movie.poster || null,
|
||||
year: movie.year || null,
|
||||
time: movie.time || null,
|
||||
episode: movie.episode || null,
|
||||
quality: movie.quality || null,
|
||||
lang: movie.lang || null,
|
||||
type: movie.type || null,
|
||||
rating: movie.rating || null,
|
||||
categories: movie.categories || null,
|
||||
countries: movie.countries || null,
|
||||
sources: movie.sources || null,
|
||||
syncedAt: new Date(),
|
||||
})
|
||||
.where(eq(movies.id, existing[0].id))
|
||||
updated++
|
||||
} else {
|
||||
await db.insert(movies).values({
|
||||
source: movie.source,
|
||||
slug: movie.slug,
|
||||
name: movie.name,
|
||||
originName: movie.originName || null,
|
||||
thumb: movie.thumb || null,
|
||||
poster: movie.poster || null,
|
||||
year: movie.year || null,
|
||||
time: movie.time || null,
|
||||
episode: movie.episode || null,
|
||||
quality: movie.quality || null,
|
||||
lang: movie.lang || null,
|
||||
type: movie.type || null,
|
||||
rating: movie.rating || null,
|
||||
categories: movie.categories || null,
|
||||
countries: movie.countries || null,
|
||||
sources: movie.sources || null,
|
||||
active: false,
|
||||
})
|
||||
created++
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
sources,
|
||||
total: allMovies.length,
|
||||
created,
|
||||
updated,
|
||||
}
|
||||
})
|
||||
@@ -1,12 +1,83 @@
|
||||
import { getKoreanMovies } from '../utils/movies'
|
||||
import { movies } from '../database/schema'
|
||||
import { desc, like, and, eq, sql } from 'drizzle-orm'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const db = useDb()
|
||||
const query = getQuery(event)
|
||||
const page = Math.max(Number(query.page || 1), 1)
|
||||
const page = Math.max(Number(query.page) || 1, 1)
|
||||
const limit = 24
|
||||
const offset = (page - 1) * limit
|
||||
const keyword = typeof query.keyword === 'string' ? query.keyword.trim() : ''
|
||||
const source = typeof query.source === 'string' && ['ophim', 'nguonc', 'kkphim'].includes(query.source)
|
||||
? query.source as 'ophim' | 'nguonc' | 'kkphim'
|
||||
: 'all'
|
||||
|
||||
return await getKoreanMovies(page, keyword, source)
|
||||
const cacheKey = `cinek:public:movies:${page}:${keyword}`
|
||||
|
||||
try {
|
||||
const redis = useRedis()
|
||||
const cached = await redis.get(cacheKey)
|
||||
if (cached) {
|
||||
return JSON.parse(cached)
|
||||
}
|
||||
} catch {}
|
||||
|
||||
const whereClause = keyword
|
||||
? and(
|
||||
eq(movies.active, true),
|
||||
like(movies.name, `%${keyword}%`),
|
||||
)
|
||||
: eq(movies.active, true)
|
||||
|
||||
const [items, countResult] = await Promise.all([
|
||||
db
|
||||
.select()
|
||||
.from(movies)
|
||||
.where(whereClause)
|
||||
.orderBy(desc(movies.syncedAt))
|
||||
.limit(limit)
|
||||
.offset(offset),
|
||||
db
|
||||
.select({ count: sql<number>`count(*)` })
|
||||
.from(movies)
|
||||
.where(whereClause),
|
||||
])
|
||||
|
||||
const total = countResult[0]?.count ?? 0
|
||||
|
||||
const result = {
|
||||
items: items.map(mapMovieToResponse),
|
||||
page,
|
||||
pagination: {
|
||||
currentPage: page,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
totalItems: total,
|
||||
},
|
||||
}
|
||||
|
||||
try {
|
||||
const redis = useRedis()
|
||||
await redis.set(cacheKey, JSON.stringify(result), 'EX', 300)
|
||||
} catch {}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
function mapMovieToResponse(movie: any) {
|
||||
return {
|
||||
id: `${movie.source}:${movie.slug}`,
|
||||
source: movie.source,
|
||||
slug: movie.slug,
|
||||
name: movie.name,
|
||||
originName: movie.originName || '',
|
||||
thumb: movie.customThumb || movie.thumb || '',
|
||||
poster: movie.customPoster || movie.poster || '',
|
||||
year: movie.year || undefined,
|
||||
time: movie.time || undefined,
|
||||
episode: movie.episode || undefined,
|
||||
quality: movie.quality || undefined,
|
||||
lang: movie.lang || undefined,
|
||||
type: movie.type || undefined,
|
||||
rating: movie.rating || undefined,
|
||||
categories: movie.categories || [],
|
||||
countries: movie.countries || [],
|
||||
sources: movie.sources || [],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { movies } from '../../database/schema'
|
||||
import { eq, and } from 'drizzle-orm'
|
||||
import { getMovieDetailGroup, parseSourceRefs } from '../../utils/movies'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
@@ -8,6 +10,27 @@ export default defineEventHandler(async (event) => {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Thiếu slug phim' })
|
||||
}
|
||||
|
||||
const source = typeof query.source === 'string' ? query.source : 'nguonc'
|
||||
const db = useDb()
|
||||
|
||||
const existing = await db
|
||||
.select()
|
||||
.from(movies)
|
||||
.where(and(eq(movies.slug, slug), eq(movies.source, source), eq(movies.active, true)))
|
||||
.limit(1)
|
||||
|
||||
if (!existing.length) {
|
||||
const fallback = await db
|
||||
.select()
|
||||
.from(movies)
|
||||
.where(and(eq(movies.slug, slug), eq(movies.active, true)))
|
||||
.limit(1)
|
||||
|
||||
if (!fallback.length) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'Phim không tồn tại hoặc đã bị ẩn' })
|
||||
}
|
||||
}
|
||||
|
||||
const refs = parseSourceRefs(query.sources || query.srcs, query.source, slug)
|
||||
|
||||
return await getMovieDetailGroup(refs)
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
CREATE TABLE `movies` (
|
||||
`id` int AUTO_INCREMENT NOT NULL,
|
||||
`source` varchar(50) NOT NULL,
|
||||
`slug` varchar(500) NOT NULL,
|
||||
`name` varchar(500) NOT NULL,
|
||||
`origin_name` varchar(500),
|
||||
`thumb` text,
|
||||
`poster` text,
|
||||
`year` int,
|
||||
`time` varchar(100),
|
||||
`episode` varchar(100),
|
||||
`quality` varchar(50),
|
||||
`lang` varchar(50),
|
||||
`type` varchar(50),
|
||||
`rating` int,
|
||||
`content` text,
|
||||
`categories` json,
|
||||
`countries` json,
|
||||
`sources` json,
|
||||
`active` boolean NOT NULL DEFAULT false,
|
||||
`synced_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`created_at` timestamp NOT NULL DEFAULT (now()),
|
||||
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT `movies_id` PRIMARY KEY(`id`)
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE `movies` ADD `custom_poster` text;--> statement-breakpoint
|
||||
ALTER TABLE `movies` ADD `custom_thumb` text;--> statement-breakpoint
|
||||
ALTER TABLE `movies` ADD `custom_content` text;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE `movies` ADD `custom_episodes` json;
|
||||
@@ -0,0 +1,194 @@
|
||||
{
|
||||
"version": "5",
|
||||
"dialect": "mysql",
|
||||
"id": "f8d4d76b-e681-4b54-8634-7ceaed266b06",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"tables": {
|
||||
"movies": {
|
||||
"name": "movies",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "int",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"source": {
|
||||
"name": "source",
|
||||
"type": "varchar(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"slug": {
|
||||
"name": "slug",
|
||||
"type": "varchar(500)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "varchar(500)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"origin_name": {
|
||||
"name": "origin_name",
|
||||
"type": "varchar(500)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"thumb": {
|
||||
"name": "thumb",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"poster": {
|
||||
"name": "poster",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"year": {
|
||||
"name": "year",
|
||||
"type": "int",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"time": {
|
||||
"name": "time",
|
||||
"type": "varchar(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"episode": {
|
||||
"name": "episode",
|
||||
"type": "varchar(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"quality": {
|
||||
"name": "quality",
|
||||
"type": "varchar(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"lang": {
|
||||
"name": "lang",
|
||||
"type": "varchar(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "varchar(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"rating": {
|
||||
"name": "rating",
|
||||
"type": "int",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"content": {
|
||||
"name": "content",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"categories": {
|
||||
"name": "categories",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"countries": {
|
||||
"name": "countries",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"sources": {
|
||||
"name": "sources",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"active": {
|
||||
"name": "active",
|
||||
"type": "boolean",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"synced_at": {
|
||||
"name": "synced_at",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(now())"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(now())"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"onUpdate": true,
|
||||
"default": "(now())"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"movies_id": {
|
||||
"name": "movies_id",
|
||||
"columns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraint": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"tables": {},
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
{
|
||||
"version": "5",
|
||||
"dialect": "mysql",
|
||||
"id": "3843ed51-a68b-4b7b-95fb-00b28b4aba56",
|
||||
"prevId": "f8d4d76b-e681-4b54-8634-7ceaed266b06",
|
||||
"tables": {
|
||||
"movies": {
|
||||
"name": "movies",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "int",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"source": {
|
||||
"name": "source",
|
||||
"type": "varchar(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"slug": {
|
||||
"name": "slug",
|
||||
"type": "varchar(500)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "varchar(500)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"origin_name": {
|
||||
"name": "origin_name",
|
||||
"type": "varchar(500)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"thumb": {
|
||||
"name": "thumb",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"poster": {
|
||||
"name": "poster",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"year": {
|
||||
"name": "year",
|
||||
"type": "int",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"time": {
|
||||
"name": "time",
|
||||
"type": "varchar(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"episode": {
|
||||
"name": "episode",
|
||||
"type": "varchar(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"quality": {
|
||||
"name": "quality",
|
||||
"type": "varchar(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"lang": {
|
||||
"name": "lang",
|
||||
"type": "varchar(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "varchar(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"rating": {
|
||||
"name": "rating",
|
||||
"type": "int",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"content": {
|
||||
"name": "content",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"categories": {
|
||||
"name": "categories",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"countries": {
|
||||
"name": "countries",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"sources": {
|
||||
"name": "sources",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"custom_poster": {
|
||||
"name": "custom_poster",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"custom_thumb": {
|
||||
"name": "custom_thumb",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"custom_content": {
|
||||
"name": "custom_content",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"active": {
|
||||
"name": "active",
|
||||
"type": "boolean",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"synced_at": {
|
||||
"name": "synced_at",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(now())"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(now())"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"onUpdate": true,
|
||||
"default": "(now())"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"movies_id": {
|
||||
"name": "movies_id",
|
||||
"columns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraint": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"tables": {},
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
{
|
||||
"version": "5",
|
||||
"dialect": "mysql",
|
||||
"id": "b3692b95-4029-4e2c-bab4-ffd0696fa2a1",
|
||||
"prevId": "3843ed51-a68b-4b7b-95fb-00b28b4aba56",
|
||||
"tables": {
|
||||
"movies": {
|
||||
"name": "movies",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "int",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"source": {
|
||||
"name": "source",
|
||||
"type": "varchar(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"slug": {
|
||||
"name": "slug",
|
||||
"type": "varchar(500)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "varchar(500)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"origin_name": {
|
||||
"name": "origin_name",
|
||||
"type": "varchar(500)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"thumb": {
|
||||
"name": "thumb",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"poster": {
|
||||
"name": "poster",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"year": {
|
||||
"name": "year",
|
||||
"type": "int",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"time": {
|
||||
"name": "time",
|
||||
"type": "varchar(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"episode": {
|
||||
"name": "episode",
|
||||
"type": "varchar(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"quality": {
|
||||
"name": "quality",
|
||||
"type": "varchar(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"lang": {
|
||||
"name": "lang",
|
||||
"type": "varchar(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "varchar(50)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"rating": {
|
||||
"name": "rating",
|
||||
"type": "int",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"content": {
|
||||
"name": "content",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"categories": {
|
||||
"name": "categories",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"countries": {
|
||||
"name": "countries",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"sources": {
|
||||
"name": "sources",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"custom_poster": {
|
||||
"name": "custom_poster",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"custom_thumb": {
|
||||
"name": "custom_thumb",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"custom_content": {
|
||||
"name": "custom_content",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"custom_episodes": {
|
||||
"name": "custom_episodes",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"active": {
|
||||
"name": "active",
|
||||
"type": "boolean",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"synced_at": {
|
||||
"name": "synced_at",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(now())"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(now())"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"onUpdate": true,
|
||||
"default": "(now())"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {
|
||||
"movies_id": {
|
||||
"name": "movies_id",
|
||||
"columns": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraint": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"tables": {},
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "mysql",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "5",
|
||||
"when": 1784692643696,
|
||||
"tag": "0000_regular_quentin_quire",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "5",
|
||||
"when": 1784693272000,
|
||||
"tag": "0001_lively_nightmare",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"version": "5",
|
||||
"when": 1784694350192,
|
||||
"tag": "0002_small_black_panther",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { mysqlTable, varchar, text, int, boolean, timestamp, json } from 'drizzle-orm/mysql-core'
|
||||
|
||||
export const movies = mysqlTable('movies', {
|
||||
id: int('id').primaryKey().autoincrement(),
|
||||
source: varchar('source', { length: 50 }).notNull(),
|
||||
slug: varchar('slug', { length: 500 }).notNull(),
|
||||
name: varchar('name', { length: 500 }).notNull(),
|
||||
originName: varchar('origin_name', { length: 500 }),
|
||||
thumb: text('thumb'),
|
||||
poster: text('poster'),
|
||||
year: int('year'),
|
||||
time: varchar('time', { length: 100 }),
|
||||
episode: varchar('episode', { length: 100 }),
|
||||
quality: varchar('quality', { length: 50 }),
|
||||
lang: varchar('lang', { length: 50 }),
|
||||
type: varchar('type', { length: 50 }),
|
||||
rating: int('rating'),
|
||||
content: text('content'),
|
||||
categories: json('categories').$type<string[]>(),
|
||||
countries: json('countries').$type<string[]>(),
|
||||
sources: json('sources').$type<{ source: string, slug: string, name?: string }[]>(),
|
||||
customPoster: text('custom_poster'),
|
||||
customThumb: text('custom_thumb'),
|
||||
customContent: text('custom_content'),
|
||||
customEpisodes: json('custom_episodes').$type<{ name: string, linkEmbed?: string, linkM3u8?: string }[]>(),
|
||||
active: boolean('active').notNull().default(false),
|
||||
syncedAt: timestamp('synced_at').notNull().defaultNow(),
|
||||
createdAt: timestamp('created_at').notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(),
|
||||
})
|
||||
|
||||
export type Movie = typeof movies.$inferSelect
|
||||
export type NewMovie = typeof movies.$inferInsert
|
||||
@@ -0,0 +1,15 @@
|
||||
import { drizzle } from 'drizzle-orm/mysql2'
|
||||
import mysql from 'mysql2/promise'
|
||||
import * as schema from '../database/schema'
|
||||
|
||||
let _db: ReturnType<typeof drizzle<typeof schema>> | undefined
|
||||
|
||||
export function useDb() {
|
||||
if (_db) return _db
|
||||
|
||||
const url = process.env.DATABASE_URL || 'mysql://cinek:cinekpassword@localhost:3306/cinek'
|
||||
const pool = mysql.createPool(url)
|
||||
|
||||
_db = drizzle(pool, { mode: 'default', schema })
|
||||
return _db
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import Redis from 'ioredis'
|
||||
|
||||
let _redis: Redis | undefined
|
||||
|
||||
export function useRedis() {
|
||||
if (_redis) return _redis
|
||||
|
||||
const url = process.env.REDIS_URL || 'redis://localhost:6379'
|
||||
_redis = new Redis(url, {
|
||||
maxRetriesPerRequest: 3,
|
||||
lazyConnect: true,
|
||||
})
|
||||
|
||||
_redis.on('error', (err) => {
|
||||
console.error('[Redis] Connection error:', err.message)
|
||||
})
|
||||
|
||||
return _redis
|
||||
}
|
||||
Reference in New Issue
Block a user