first commit
This commit is contained in:
48
scripts/create-admin.js
Normal file
48
scripts/create-admin.js
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
const { createClient } = require('@supabase/supabase-js');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Read .env.local manually since we might not have dotenv installed
|
||||
const envPath = path.resolve(process.cwd(), '.env.local');
|
||||
const envContent = fs.readFileSync(envPath, 'utf-8');
|
||||
|
||||
const env = {};
|
||||
envContent.split('\n').forEach(line => {
|
||||
const [key, value] = line.split('=');
|
||||
if (key && value) {
|
||||
env[key.trim()] = value.trim();
|
||||
}
|
||||
});
|
||||
|
||||
const supabaseUrl = env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const supabaseKey = env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
|
||||
|
||||
if (!supabaseUrl || !supabaseKey) {
|
||||
console.error('Error: NEXT_PUBLIC_SUPABASE_URL or NEXT_PUBLIC_SUPABASE_ANON_KEY not found in .env.local');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const supabase = createClient(supabaseUrl, supabaseKey);
|
||||
|
||||
async function createUser() {
|
||||
console.log('Attempting to create user: admin@admin.com');
|
||||
|
||||
const { data, error } = await supabase.auth.signUp({
|
||||
email: 'admin@admin.com',
|
||||
password: 'Admin123@',
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error('Error creating user:', error.message);
|
||||
} else {
|
||||
console.log('User created successfully:', data.user);
|
||||
if (data.session) {
|
||||
console.log('Session active. User is logged in.');
|
||||
} else {
|
||||
console.log('User created but no session. Email confirmation might be required depending on your Supabase settings.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
createUser();
|
||||
28
scripts/debug-rank.js
Normal file
28
scripts/debug-rank.js
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
const BASE_URL = "https://mapi.geofani.online/api";
|
||||
|
||||
async function fetchJson(url) {
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) throw new Error(`Fetch failed: ${res.status}`);
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
async function debug() {
|
||||
try {
|
||||
console.log("Fetching Rank...");
|
||||
const json = await fetchJson(`${BASE_URL}/rank`);
|
||||
console.log("Keys:", Object.keys(json));
|
||||
|
||||
if (json.movie && json.movie.length > 0) {
|
||||
console.log("Top Movie:", json.movie[0].title, json.movie[0].imdbRatingValue);
|
||||
}
|
||||
if (json.tv && json.tv.length > 0) {
|
||||
console.log("Top Series:", json.tv[0].title, json.tv[0].imdbRatingValue);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error("Debug failed:", e);
|
||||
}
|
||||
}
|
||||
|
||||
debug();
|
||||
28
scripts/debug-search.js
Normal file
28
scripts/debug-search.js
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
const BASE_URL = "https://mapi.geofani.online/api";
|
||||
|
||||
async function fetchJson(url) {
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) throw new Error(`Fetch failed: ${res.status}`);
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
async function debug() {
|
||||
try {
|
||||
console.log("Fetching Search 'a'...");
|
||||
const json = await fetchJson(`${BASE_URL}/search?keyword=a&page=1`);
|
||||
// Check if search response has a pager or total
|
||||
console.log("Keys:", Object.keys(json));
|
||||
if (json.pager) {
|
||||
console.log("Search Pager:", JSON.stringify(json.pager, null, 2));
|
||||
} else {
|
||||
console.log("No pager in search response.");
|
||||
console.log("Items length:", Array.isArray(json) ? json.length : (json.items ? json.items.length : 'unknown'));
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error("Debug failed:", e);
|
||||
}
|
||||
}
|
||||
|
||||
debug();
|
||||
38
scripts/debug-sources.js
Normal file
38
scripts/debug-sources.js
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
const BASE_URL = "https://mapi.geofani.online/api";
|
||||
const subjectId = "8955962000002143264"; // Monster ID
|
||||
|
||||
async function fetchJson(url) {
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) throw new Error(`Fetch failed: ${res.status}`);
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
async function debug() {
|
||||
try {
|
||||
console.log("Fetching Detail...");
|
||||
const detail = await fetchJson(`${BASE_URL}/detail?url=${subjectId}`);
|
||||
// Log resource structure to see seasons/episodes
|
||||
console.log("Detail Resource:", JSON.stringify(detail.resource, null, 2));
|
||||
|
||||
console.log("\nFetching Sources (0, 0)...");
|
||||
try {
|
||||
const json0 = await fetchJson(`${BASE_URL}/sources?subjectId=${subjectId}`);
|
||||
console.log("Sources (0,0):", json0.downloads ? json0.downloads.length : 0, "processed:", json0.processedSources ? json0.processedSources.length : 0);
|
||||
} catch (e) {
|
||||
console.log("Sources (0,0) failed:", e.message);
|
||||
}
|
||||
|
||||
console.log("\nFetching Sources (1, 1)...");
|
||||
try {
|
||||
const json1 = await fetchJson(`${BASE_URL}/sources?subjectId=${subjectId}&season=1&episode=1`);
|
||||
console.log("Sources (1,1):", json1.downloads ? json1.downloads.length : 0, "processed:", json1.processedSources ? json1.processedSources.length : 0);
|
||||
} catch (e) {
|
||||
console.log("Sources (1,1) failed:", e.message);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Debug failed:", e);
|
||||
}
|
||||
}
|
||||
|
||||
debug();
|
||||
29
scripts/debug-trending.js
Normal file
29
scripts/debug-trending.js
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
const BASE_URL = "https://mapi.geofani.online/api";
|
||||
|
||||
async function fetchJson(url) {
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) throw new Error(`Fetch failed: ${res.status}`);
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
async function debug() {
|
||||
try {
|
||||
console.log("Fetching Trending...");
|
||||
const json = await fetchJson(`${BASE_URL}/trending?page=1`);
|
||||
console.log("Pager:", JSON.stringify(json.pager, null, 2));
|
||||
|
||||
if (json.pager) {
|
||||
console.log("Total Count:", json.pager.totalCount);
|
||||
} else {
|
||||
console.log("No pager found");
|
||||
}
|
||||
|
||||
console.log("Subject List Length:", json.subjectList ? json.subjectList.length : 0);
|
||||
|
||||
} catch (e) {
|
||||
console.error("Debug failed:", e);
|
||||
}
|
||||
}
|
||||
|
||||
debug();
|
||||
72
scripts/set-admin-role.js
Normal file
72
scripts/set-admin-role.js
Normal file
@@ -0,0 +1,72 @@
|
||||
|
||||
const { createClient } = require('@supabase/supabase-js');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Read .env.local manually
|
||||
const envPath = path.resolve(process.cwd(), '.env.local');
|
||||
const envContent = fs.readFileSync(envPath, 'utf-8');
|
||||
|
||||
const env = {};
|
||||
envContent.split('\n').forEach(line => {
|
||||
const [key, value] = line.split('=');
|
||||
if (key && value) {
|
||||
env[key.trim()] = value.trim();
|
||||
}
|
||||
});
|
||||
|
||||
const supabaseUrl = env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const serviceKey = env.SUPABASE_SERVICE_ROLE_KEY;
|
||||
|
||||
if (!supabaseUrl || !serviceKey) {
|
||||
console.error('Error: NEXT_PUBLIC_SUPABASE_URL or SUPABASE_SERVICE_ROLE_KEY not found in .env.local');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const supabase = createClient(supabaseUrl, serviceKey, {
|
||||
auth: {
|
||||
autoRefreshToken: false,
|
||||
persistSession: false
|
||||
}
|
||||
});
|
||||
|
||||
async function setAdminRole() {
|
||||
const email = 'admin@admin.com';
|
||||
console.log(`Searching for user: ${email}...`);
|
||||
|
||||
// 1. Find user by email (using listUsers for simplicity as there is no straight getUserByEmail in admin api sometimes depending on version, but listUsers is safe)
|
||||
// Actually getUserByEmail exists in newer versions but listUsers is robust.
|
||||
// Let's try listUsers with filter if possible, or just list all.
|
||||
|
||||
// In @supabase/supabase-js v2, listUsers doesn't support email filter directly in all versions cleanly, so we'll fetch and find.
|
||||
const { data: { users }, error } = await supabase.auth.admin.listUsers();
|
||||
|
||||
if (error) {
|
||||
console.error('Error listing users:', error.message);
|
||||
return;
|
||||
}
|
||||
|
||||
const user = users.find(u => u.email === email);
|
||||
|
||||
if (!user) {
|
||||
console.error(`User ${email} not found! Please run the create-admin script first or sign up.`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Found user ${user.id}. Setting role to 'admin'...`);
|
||||
|
||||
// 2. Update user metadata
|
||||
const { data: updatedUser, error: updateError } = await supabase.auth.admin.updateUserById(
|
||||
user.id,
|
||||
{ app_metadata: { role: 'admin' } }
|
||||
);
|
||||
|
||||
if (updateError) {
|
||||
console.error('Error updating user role:', updateError.message);
|
||||
} else {
|
||||
console.log(`Success! User ${email} is now an admin.`);
|
||||
console.log('App Metadata:', updatedUser.user.app_metadata);
|
||||
}
|
||||
}
|
||||
|
||||
setAdminRole();
|
||||
22
scripts/test-dracin-api.js
Normal file
22
scripts/test-dracin-api.js
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
const BASE_URL = "https://dapi.geofani.online";
|
||||
|
||||
async function testDetail() {
|
||||
try {
|
||||
const id = "42000002888"; // ID from user example
|
||||
console.log(`Fetching detail for ${id}...`);
|
||||
const res = await fetch(`${BASE_URL}/api/detail/${id}/v2?lang=in`);
|
||||
const json = await res.json();
|
||||
|
||||
if (json.success && json.data && json.data.drama) {
|
||||
console.log("Drama Name:", json.data.drama.name);
|
||||
console.log("Drama Cover:", json.data.drama.cover);
|
||||
} else {
|
||||
console.log("Failed or invalid structure:", JSON.stringify(json, null, 2));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
testDetail();
|
||||
35
scripts/test-recommend.js
Normal file
35
scripts/test-recommend.js
Normal file
@@ -0,0 +1,35 @@
|
||||
// const fetch = require('node-fetch'); // Built-in in Node 18+
|
||||
|
||||
const BASE_URL = "http://localhost:7000";
|
||||
|
||||
async function testRecommend() {
|
||||
try {
|
||||
console.log("Fetching /api/recommend...");
|
||||
const res = await fetch(`${BASE_URL}/api/recommend?page=1&size=20&lang=in`);
|
||||
|
||||
console.log("Status:", res.status);
|
||||
const text = await res.text();
|
||||
console.log("Raw text length:", text.length);
|
||||
console.log("Raw text start:", text.slice(0, 500));
|
||||
|
||||
try {
|
||||
const json = JSON.parse(text);
|
||||
console.log("Parsed JSON Success:", json.success);
|
||||
|
||||
if (json.data) {
|
||||
const keys = Object.keys(json.data);
|
||||
console.log("Keys in data:", keys);
|
||||
if (Array.isArray(json.data) && json.data.length > 0) {
|
||||
console.log("First item sample:", JSON.stringify(json.data[0], null, 2));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("JSON Parse Error:", e.message);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error("Fetch Error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
testRecommend();
|
||||
Reference in New Issue
Block a user