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

5
.firebaserc Normal file
View File

@@ -0,0 +1,5 @@
{
"projects": {
"default": "map-jurnal"
}
}

7
cors.json Normal file
View File

@@ -0,0 +1,7 @@
[
{
"origin": ["http://localhost:5173", "https://map-jurnal.web.app", "https://map-jurnal.firebaseapp.com"],
"method": ["GET", "HEAD", "PUT", "POST", "DELETE"],
"maxAgeSeconds": 3600
}
]

5
firebase.json Normal file
View File

@@ -0,0 +1,5 @@
{
"storage": {
"rules": "storage.rules"
}
}

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!');
}

View File

@@ -123,7 +123,7 @@
background: #8b5cf6;
color: #fff;
font-size: 15px;
font-weight: 600;
font-weight: 500;
gap: 6px;
cursor: pointer;
display: flex;

View File

@@ -137,7 +137,7 @@
cursor: pointer;
font-family: var(--sans);
font-size: 14px;
font-weight: 300;
font-weight: 500;
color: var(--text);
letter-spacing: 0.01em;
transition: color 0.2s ease;

9
storage.rules Normal file
View File

@@ -0,0 +1,9 @@
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read: if true;
allow write: if request.auth != null;
}
}
}