Spaces:
Sleeping
Sleeping
| import fs from 'fs'; | |
| import path from 'path'; | |
| import { createClient } from '@supabase/supabase-js'; | |
| // Parse .env manually | |
| const envPath = path.resolve('.env'); | |
| if (!fs.existsSync(envPath)) { | |
| console.error("Error: .env file not found at", envPath); | |
| process.exit(1); | |
| } | |
| const envContent = fs.readFileSync(envPath, 'utf-8'); | |
| const env = {}; | |
| envContent.split('\n').forEach(line => { | |
| const trimmed = line.trim(); | |
| if (trimmed.startsWith('#') || !trimmed) return; | |
| const match = trimmed.match(/^([^=]+)=(.*)$/); | |
| if (match) { | |
| env[match[1].trim()] = match[2].trim(); | |
| } | |
| }); | |
| const supabaseUrl = env.PUBLIC_SUPABASE_URL; | |
| const supabaseAnonKey = env.PUBLIC_SUPABASE_ANON_KEY; | |
| if (!supabaseUrl || !supabaseAnonKey) { | |
| console.error("Error: Supabase URL or Anon Key is missing in .env!"); | |
| process.exit(1); | |
| } | |
| const supabase = createClient(supabaseUrl, supabaseAnonKey); | |
| async function run() { | |
| try { | |
| const srtPath = "C:\\Users\\TXA3100\\Desktop\\VIETSUB\\sut_vi.srt"; | |
| if (!fs.existsSync(srtPath)) { | |
| console.error("Error: SRT file not found at", srtPath); | |
| process.exit(1); | |
| } | |
| const srtContent = fs.readFileSync(srtPath, 'utf-8'); | |
| console.log("Read SRT subtitle successfully. Length:", srtContent.length); | |
| const movie_json = { | |
| "_id": "fbi-part-one-id", | |
| "imdb": { "id": null }, | |
| "lang": "Vietsub", | |
| "name": "FBI: Part One", | |
| "slug": "fbi-part-one", | |
| "time": "120 phút", | |
| "tmdb": { "id": null, "type": "movie", "season": 1, "vote_count": 0, "vote_average": 0 }, | |
| "type": "single", | |
| "view": 0, | |
| "year": 2026, | |
| "actor": ["FBI Agents"], | |
| "notify": "", | |
| "status": "completed", | |
| "content": "Bộ phim hành động FBI Part One cực kỳ kịch tính và hấp dẫn, đi kèm hệ thống Storyboard dynamic youtube-style mượt mà và chất lượng đa luồng chất lượng cao.", | |
| "country": [{ "id": "usa", "name": "Mỹ", "slug": "my" }], | |
| "created": { "time": "2026-05-18T14:40:00.000Z" }, | |
| "quality": "HD", | |
| "category": [{ "id": "action", "name": "Hành Động", "slug": "hanh-dong" }], | |
| "chieurap": false, | |
| "director": ["FBI Directors"], | |
| "modified": { "time": "2026-05-18T14:40:00.000Z" }, | |
| "showtimes": "", | |
| "thumb_url": "https://phimimg.com/upload/vod/20260307-1/81572d43eddf1dc784f3f53f6323f46d.jpg", | |
| "poster_url": "https://phimimg.com/upload/vod/20260307-1/7e5b11b1d5ce3514f6d62787d164b816.jpg", | |
| "origin_name": "FBI Part One", | |
| "trailer_url": "", | |
| "is_copyright": false, | |
| "sub_docquyen": false, | |
| "episode_total": "1", | |
| "episode_current": "Full" | |
| }; | |
| const episodes_json = [ | |
| { | |
| "server_name": "Cloudflare R2 Premium", | |
| "server_data": [ | |
| { | |
| "name": "Full Movie", | |
| "slug": "full-movie", | |
| "filename": "FBI Part One - Full HD - Vietsub", | |
| "link_m3u8": "https://tphimx-r2-proxy.txagt145.workers.dev/fbi-part-one/master.m3u8", | |
| "link_embed": "https://tphimx-r2-proxy.txagt145.workers.dev/fbi-part-one/master.m3u8", | |
| "subtitles_srt": srtContent | |
| } | |
| ] | |
| } | |
| ]; | |
| console.log("Upserting movie record to public.movies for slug 'fbi-part-one'..."); | |
| const { data, error } = await supabase | |
| .from('movies') | |
| .upsert({ | |
| slug: 'fbi-part-one', | |
| movie: movie_json, | |
| episodes: episodes_json, | |
| updated_at: new Date().toISOString() | |
| }) | |
| .select(); | |
| if (error) { | |
| throw error; | |
| } | |
| console.log("Success! Movie 'fbi-part-one' has been successfully registered/updated with SRT subtitles."); | |
| console.log("Result rows:", data ? data.length : 0); | |
| } catch (err) { | |
| console.error("Error executing database upsert:", err); | |
| process.exit(1); | |
| } | |
| } | |
| run(); | |