added saving photos to firebase

This commit is contained in:
2026-06-16 23:18:20 +09:00
parent d614ddb322
commit 1743e7fcbe
9 changed files with 107 additions and 2 deletions

11
scripts/get-token.mjs Normal file
View File

@@ -0,0 +1,11 @@
import { getAccessToken } from 'firebase-tools';
import { writeFileSync } from 'fs';
(async () => {
try {
const token = await getAccessToken();
writeFileSync('token.txt', token);
console.log('Token saved');
} catch (e) {
console.error('Failed:', e.message);
}
})();

36
scripts/set-cors.mjs Normal file
View File

@@ -0,0 +1,36 @@
import { readFileSync } from 'fs';
const config = JSON.parse(readFileSync(
'C:\\Users\\tomas\\.config\\configstore\\firebase-tools.json', 'utf-8'
));
const token = config.tokens.access_token;
// Try to list buckets first
const listRes = await fetch('https://storage.googleapis.com/storage/v1/b?project=map-jurnal', {
headers: { Authorization: `Bearer ${token}` },
});
const buckets = await listRes.json();
console.log('Buckets:', buckets.items?.map(b => b.name) ?? buckets);
const bucket = 'map-jurnal.appspot.com';
const corsConfig = [{
origin: ['http://localhost:5173', 'https://map-jurnal.web.app', 'https://map-jurnal.firebaseapp.com'],
method: ['GET', 'HEAD', 'PUT', 'POST', 'DELETE'],
maxAgeSeconds: 3600,
}];
const res = await fetch(`https://storage.googleapis.com/storage/v1/b/${bucket}`, {
method: 'PATCH',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ cors: corsConfig }),
});
if (res.ok) {
console.log('CORS configured successfully!');
} else {
const text = await res.text();
console.error('Failed:', res.status, text);
}

32
scripts/set-cors2.mjs Normal file
View File

@@ -0,0 +1,32 @@
import { readFileSync } from 'fs';
import { Storage } from '@google-cloud/storage';
const config = JSON.parse(readFileSync('C:/Users/tomas/.config/configstore/firebase-tools.json', 'utf-8'));
const storage = new Storage({
projectId: 'map-jurnal',
credentials: {
client_email: 'firebase-cli@map-jurnal.iam.gserviceaccount.com',
// We'll use token-based auth instead
},
});
// Try with direct token
const token = config.tokens.access_token;
// List all buckets to find the right name
const [buckets] = await storage.getBuckets({ project: 'map-jurnal' });
console.log('Buckets:', buckets.map(b => b.name));
if (buckets.length > 0) {
const bucket = buckets[0];
console.log('Configuring CORS for:', bucket.name);
await bucket.setCorsConfiguration([
{
origin: ['http://localhost:5173', 'https://map-jurnal.web.app', 'https://map-jurnal.firebaseapp.com'],
method: ['GET', 'HEAD', 'PUT', 'POST', 'DELETE'],
maxAgeSeconds: 3600,
},
]);
console.log('CORS configured!');
}