added saving photos to firebase
This commit is contained in:
5
.firebaserc
Normal file
5
.firebaserc
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"projects": {
|
||||||
|
"default": "map-jurnal"
|
||||||
|
}
|
||||||
|
}
|
||||||
7
cors.json
Normal file
7
cors.json
Normal 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
5
firebase.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"storage": {
|
||||||
|
"rules": "storage.rules"
|
||||||
|
}
|
||||||
|
}
|
||||||
11
scripts/get-token.mjs
Normal file
11
scripts/get-token.mjs
Normal 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
36
scripts/set-cors.mjs
Normal 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
32
scripts/set-cors2.mjs
Normal 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!');
|
||||||
|
}
|
||||||
@@ -123,7 +123,7 @@
|
|||||||
background: #8b5cf6;
|
background: #8b5cf6;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
font-weight: 600;
|
font-weight: 500;
|
||||||
gap: 6px;
|
gap: 6px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -137,7 +137,7 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-family: var(--sans);
|
font-family: var(--sans);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 300;
|
font-weight: 500;
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
letter-spacing: 0.01em;
|
letter-spacing: 0.01em;
|
||||||
transition: color 0.2s ease;
|
transition: color 0.2s ease;
|
||||||
|
|||||||
9
storage.rules
Normal file
9
storage.rules
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user