Smashed some bugs; migrated to caprover appwrite

This commit is contained in:
2023-05-16 13:39:54 -04:00
parent 1134979fb5
commit 528d75470f
14 changed files with 2183 additions and 77 deletions
+17 -2
View File
@@ -6,18 +6,33 @@ const sdk = require('node-appwrite')
const client = new sdk.Client()
const databases = new sdk.Databases(client)
const strftime = require('strftime')
const { entries } = require('./import.js')
const { importCSV } = require('./import.js')
client
.setEndpoint('http://ryanpandya.com:8080/v1') // Your API Endpoint
.setEndpoint('https://db.ryanpandya.com/v1') // Your API Endpoint
.setProject('lifetracker') // Your project ID
.setKey('015d60dd9dc8fb1b34b9f66459a27b3aded55c93a5b551d78be7a48b94f26e1781020a65407116265e3d93fac9d99e717b676c158bdda351aae22877da8f8b14af4d310d8fe3d4e3005adcc0f228b95f7efae308e638610bd97f9d44e8c322c07f38f9ba17a264efb65d3601c5302c2a5072cd294e69d9baacd19ba9ec9a117f') // Your secret API key
;
const app = express()
// Import multer like the other dependencies
const multer = require('multer')
// Set multer file storage folder
const upload = multer({ dest: 'uploads/' })
app.use(morgan('combined'))
app.use(bodyParser.json())
app.use(cors())
app.get('/import', (req, res) => {
res.send("<form method='POST' enctype='multipart/form-data' action='/import' style='width: 500px; margin: 0 auto; gap: 1em; display:flex;flex-direction:column;'><h1>Import CSV</h1><input type='file' name='csv'/><button type='submit'>Import</button></form>");
})
app.post('/import', upload.single('csv'), (req, res) => {
numEntries = importCSV(req.file.path)
res.send("<div style='margin: 0 auto; width: 500px;'><h1>Import CSV</h1>Imported " + numEntries + " from '" + req.file.path + "'.</div>");
})
// app.get('/database', (req, res) => {
// const promise = databases.listDocuments('lifetracker-db', 'ryan');
// promise.then(function ({ documents } = response) {
File diff suppressed because one or more lines are too long
+12 -8
View File
@@ -8,17 +8,20 @@ const client = new sdk.Client();
const databases = new sdk.Databases(client);
function importCSV(){
console.log("Worked.");
function importsCSV(path){
console.log(fs.readFileSync(path))
console.log("Worked.")
return 42
}
function importsCSV(){
var data = fs.readFileSync('data.csv')
function importCSV(path){
var data = fs.readFileSync(path)
.toString() // convert Buffer to string
.split('\n') // split string to lines
.slice(1) // remove first line
.map(e => e.trim()) // remove white spaces for each line
.map(e => {
data.map(e => {
var entry = e.split(','); // split each line to array
var date = strftime("%Y-%m-%d", new Date("2023/" + entry[0]));
var hours = entry.slice(2, 26).map(h => parseFloat(h));
@@ -32,9 +35,9 @@ function importsCSV(){
comments: comments
};
client
.setEndpoint('http://ryanpandya.com:8080/v1') // Your API Endpoint
.setEndpoint('https://db.ryanpandya.com/v1') // Your API Endpoint
.setProject('lifetracker') // Your project ID
.setKey('015d60dd9dc8fb1b34b9f66459a27b3aded55c93a5b551d78be7a48b94f26e1781020a65407116265e3d93fac9d99e717b676c158bdda351aae22877da8f8b14af4d310d8fe3d4e3005adcc0f228b95f7efae308e638610bd97f9d44e8c322c07f38f9ba17a264efb65d3601c5302c2a5072cd294e69d9baacd19ba9ec9a117f') // Your secret API key
.setKey('3838a1b48dc55219876ef6bdd379b65128775e6b300021d4691d7001c30a08126f29d36c18554633463e897fe07bb651fff51c73ad85c7a86468cea3ac6bab80e42942ab717e46b9e23fd4bb262455ec89be6275e44b2b4765c0d10c0789bad8f92de4b4f3f3410a5b2fd9c994a5434cd66ca35926fdeed139c9b84154721a84') // Your secret API key
const promise = databases.createDocument('lifetracker-db', 'ryan', date, dbEntry);
@@ -45,6 +48,7 @@ function importsCSV(){
console.log(error);
});
})
return data.length
}
exports.entries = importCSV;
exports.importCSV = importCSV;