-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_books.js
More file actions
69 lines (57 loc) · 2.17 KB
/
Copy pathcheck_books.js
File metadata and controls
69 lines (57 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { createClient } = require('@supabase/supabase-js');
// Since I don't have the process.env keys here, I'll rely on the user having them in .env.local usually,
// but for a script I might need to read the file.
// Or I can just use a tool to grep them.
// Wait, I can't read .env.local directly usually safely if it's not committed, but I am in the user env.
// Let's try to read .env.local first to get keys.
const fs = require('fs');
const path = require('path');
const envPath = path.resolve(__dirname, '.env.local');
let SUPABASE_URL = '';
let SUPABASE_ANON_KEY = '';
try {
const envConfig = fs.readFileSync(envPath, 'utf8');
const lines = envConfig.split('\n');
lines.forEach(line => {
const parts = line.split('=');
if (parts.length >= 2) {
const key = parts[0].trim();
const val = parts.slice(1).join('=').trim().replace(/"/g, '');
if (key === 'NEXT_PUBLIC_SUPABASE_URL') SUPABASE_URL = val;
if (key === 'NEXT_PUBLIC_SUPABASE_ANON_KEY') SUPABASE_ANON_KEY = val;
}
});
} catch (e) {
console.error("Could not read .env.local");
}
if (!SUPABASE_URL || !SUPABASE_ANON_KEY) {
console.error("Missing Supabase keys");
process.exit(1);
}
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
async function checkRooms() {
console.log("Checking rooms...");
const { data, error } = await supabase.from('rooms').select('id, name, epub_url');
if (error) {
console.error("Error fetching rooms:", error);
return;
}
console.log(`Found ${data.length} rooms.`);
for (const room of data) {
console.log(`Room: ${room.name} (${room.id})`);
console.log(` epub_url: ${room.epub_url}`);
if (room.epub_url) {
try {
// Check if URL is accessible
const res = await fetch(room.epub_url, { method: 'HEAD' });
console.log(` Url Status: ${res.status} ${res.statusText}`);
} catch (e) {
console.log(` Url Check Failed: ${e.message}`);
}
} else {
console.log(" No epub_url!");
}
console.log("---");
}
}
checkRooms();