mirror of
https://codeberg.org/JasterV/sentences-crud.git
synced 2026-04-26 18:10:05 +00:00
firebase.json not required
This commit is contained in:
parent
dab927302f
commit
4edd34078d
5 changed files with 84 additions and 51 deletions
12
.env.example
12
.env.example
|
|
@ -1,3 +1,13 @@
|
||||||
API_SECRET=
|
API_SECRET=
|
||||||
DEEPL_KEY=
|
DEEPL_KEY=
|
||||||
DEEPL_URL=
|
DEEPL_URL=
|
||||||
|
FB_CERT_TYPE=
|
||||||
|
FB_CERT_PROJECT_ID=
|
||||||
|
FB_CERT_PRIVATE_KEY_ID=
|
||||||
|
FB_CERT_PRIVATE_KEY=
|
||||||
|
FB_CERT_CLIENT_EMAIL=
|
||||||
|
FB_CERT_CLIENT_ID=
|
||||||
|
FB_CERT_AUTH_URI=
|
||||||
|
FB_CERT_TOKEN_URI=
|
||||||
|
FB_CERT_AUTH_PROVIDER_X509_CERT_URL=
|
||||||
|
FB_CERT_CLIENT_X509_CERT_URL=
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"type": "",
|
|
||||||
"project_id": "",
|
|
||||||
"private_key_id": "",
|
|
||||||
"private_key": "",
|
|
||||||
"client_email": "",
|
|
||||||
"client_id": "",
|
|
||||||
"auth_uri": "",
|
|
||||||
"token_uri": "",
|
|
||||||
"auth_provider_x509_cert_url": "",
|
|
||||||
"client_x509_cert_url": ""
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +1,47 @@
|
||||||
const admin = require('firebase-admin')
|
const admin = require('firebase-admin')
|
||||||
const serviceAccount = require("../.firebase.json");
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const readline = require('readline');
|
const readline = require('readline');
|
||||||
|
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
|
|
||||||
if (args.length != 1) {
|
if (args.length != 2) {
|
||||||
console.log('Dataset path required: ')
|
console.log('Dataset path required')
|
||||||
console.log('nodejs upload_dataset.js <dataset-path>')
|
console.log('Firebase service account file required')
|
||||||
|
console.log('nodejs upload_dataset.js <account-file> <dataset-path>')
|
||||||
process.exit(-1)
|
process.exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
const dataFilePath = args[0]
|
const serviceAccount = require(args[0]);
|
||||||
(async () => {
|
const dataFilePath = args[1];
|
||||||
admin.initializeApp({
|
|
||||||
credential: admin.credential.cert(serviceAccount)
|
|
||||||
});
|
|
||||||
|
|
||||||
const db = admin.firestore()
|
(async () => {
|
||||||
|
admin.initializeApp({
|
||||||
|
credential: admin.credential.cert(serviceAccount)
|
||||||
|
});
|
||||||
|
|
||||||
console.log('Firestore credentials ok')
|
const db = admin.firestore()
|
||||||
|
|
||||||
const rl = readline.createInterface({
|
console.log('Firestore credentials ok')
|
||||||
input: fs.createReadStream(dataFilePath),
|
|
||||||
output: process.stdout,
|
|
||||||
terminal: false
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('Reading sentences.jsonl.txt')
|
const rl = readline.createInterface({
|
||||||
console.log('Importing data to firebase...')
|
input: fs.createReadStream(dataFilePath),
|
||||||
|
output: process.stdout,
|
||||||
|
terminal: false
|
||||||
|
});
|
||||||
|
|
||||||
rl.on('line', async (line) => {
|
console.log('Reading sentences.jsonl.txt')
|
||||||
const sentence = JSON.parse(line)
|
console.log('Importing data to firebase...')
|
||||||
const entry = Object.entries(sentence.cats).find((elem) => elem['1'] == 1)
|
|
||||||
if (!entry) {
|
rl.on('line', async (line) => {
|
||||||
console.log('Sentence: ', sentence, ' does not have a category')
|
const sentence = JSON.parse(line)
|
||||||
return
|
const entry = Object.entries(sentence.cats).find((elem) => elem['1'] == 1)
|
||||||
}
|
if (!entry) {
|
||||||
await db.collection('sentences').doc().set({
|
console.log('Sentence: ', sentence, ' does not have a category')
|
||||||
text: sentence.text,
|
return
|
||||||
category: entry[0]
|
}
|
||||||
})
|
await db.collection('sentences').doc().set({
|
||||||
});
|
text: sentence.text,
|
||||||
})();
|
category: entry[0]
|
||||||
|
})
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,32 @@ const {
|
||||||
PORT = 8080,
|
PORT = 8080,
|
||||||
API_SECRET,
|
API_SECRET,
|
||||||
DEEPL_KEY,
|
DEEPL_KEY,
|
||||||
DEEPL_URL
|
DEEPL_URL,
|
||||||
|
FB_CERT_TYPE,
|
||||||
|
FB_CERT_PROJECT_ID,
|
||||||
|
FB_CERT_PRIVATE_KEY_ID,
|
||||||
|
FB_CERT_PRIVATE_KEY,
|
||||||
|
FB_CERT_CLIENT_EMAIL,
|
||||||
|
FB_CERT_CLIENT_ID,
|
||||||
|
FB_CERT_AUTH_URI,
|
||||||
|
FB_CERT_TOKEN_URI,
|
||||||
|
FB_CERT_AUTH_PROVIDER_X509_CERT_URL,
|
||||||
|
FB_CERT_CLIENT_X509_CERT_URL,
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
if(!API_SECRET) throw new Error('API_SECRET required but not found')
|
if (!API_SECRET) throw new Error('API_SECRET required but not found')
|
||||||
if(!DEEPL_KEY) throw new Error('DEEPL_KEY required but not found')
|
if (!DEEPL_KEY) throw new Error('DEEPL_KEY required but not found')
|
||||||
if(!DEEPL_URL) throw new Error('DEEPL_URL required but not found')
|
if (!DEEPL_URL) throw new Error('DEEPL_URL required but not found')
|
||||||
|
if (!FB_CERT_TYPE) throw new Error('FB_CERT_TYPE required but not found')
|
||||||
|
if (!FB_CERT_PROJECT_ID) throw new Error('FB_CERT_PROJECT_ID required but not found')
|
||||||
|
if (!FB_CERT_PRIVATE_KEY_ID) throw new Error('FB_CERT_PRIVATE_KEY_ID required but not found')
|
||||||
|
if (!FB_CERT_PRIVATE_KEY) throw new Error('FB_CERT_PRIVATE_KEY required but not found')
|
||||||
|
if (!FB_CERT_CLIENT_EMAIL) throw new Error('FB_CERT_CLIENT_EMAIL required but not found')
|
||||||
|
if (!FB_CERT_CLIENT_ID) throw new Error('FB_CERT_CLIENT_ID required but not found')
|
||||||
|
if (!FB_CERT_AUTH_URI) throw new Error('FB_CERT_AUTH_URI required but not found')
|
||||||
|
if (!FB_CERT_TOKEN_URI) throw new Error('FB_CERT_TOKEN_URI required but not found')
|
||||||
|
if (!FB_CERT_AUTH_PROVIDER_X509_CERT_URL) throw new Error('FB_CERT_AUTH_PROVIDER_X509_CERT_URL required but not found')
|
||||||
|
if (!FB_CERT_CLIENT_X509_CERT_URL) throw new Error('FB_CERT_CLIENT_X509_CERT_URL required but not found')
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
env: NODE_ENV,
|
env: NODE_ENV,
|
||||||
|
|
@ -21,6 +41,20 @@ const config = {
|
||||||
deepl: {
|
deepl: {
|
||||||
key: DEEPL_KEY,
|
key: DEEPL_KEY,
|
||||||
url: DEEPL_URL
|
url: DEEPL_URL
|
||||||
|
},
|
||||||
|
firebase: {
|
||||||
|
credentials: {
|
||||||
|
type: FB_CERT_TYPE,
|
||||||
|
project_id: FB_CERT_PROJECT_ID,
|
||||||
|
private_key_id: FB_CERT_PRIVATE_KEY_ID,
|
||||||
|
private_key: FB_CERT_PRIVATE_KEY.replace(/\\n/g, '\n'),
|
||||||
|
client_email: FB_CERT_CLIENT_EMAIL,
|
||||||
|
client_id: FB_CERT_CLIENT_ID,
|
||||||
|
auth_uri: FB_CERT_AUTH_URI,
|
||||||
|
token_uri: FB_CERT_TOKEN_URI,
|
||||||
|
auth_provider_x509_cert_url: FB_CERT_AUTH_PROVIDER_X509_CERT_URL,
|
||||||
|
client_x509_cert_url: FB_CERT_CLIENT_X509_CERT_URL,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import * as admin from 'firebase-admin'
|
import * as admin from 'firebase-admin'
|
||||||
|
import config from '../config';
|
||||||
const serviceAccount = require("../../.firebase.json");
|
|
||||||
|
|
||||||
admin.initializeApp({
|
admin.initializeApp({
|
||||||
credential: admin.credential.cert(serviceAccount)
|
credential: admin.credential.cert(config.firebase.credentials as any)
|
||||||
});
|
});
|
||||||
|
|
||||||
const db = admin.firestore()
|
const db = admin.firestore()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue