-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4433367
commit 1de5dfa
Showing
16 changed files
with
757 additions
and
468 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
const { app } = require('electron'); | ||
|
||
// types that we support downloading | ||
const DOWNLOADABLE_MIME_TYPES = [ | ||
// video | ||
'application/mp4', | ||
'application/ogg', | ||
'video/mp4', | ||
'video/ogg', | ||
'video/quicktime', | ||
'video/webm', | ||
// audio | ||
'audio/mp4', | ||
'audio/mpeg', | ||
'audio/ogg', | ||
'audio/webm', | ||
'audio/x-aac', | ||
'audio/x-wav', | ||
// image | ||
'image/bmp', | ||
'image/gif', | ||
'image/jpeg', | ||
'image/png', | ||
'application/pdf', | ||
]; | ||
|
||
// categories | ||
const RESOURCE = 'Resource'; | ||
const APPLICATION = 'Application'; | ||
|
||
const VAR_FOLDER = `${app.getPath('userData')}/var`; | ||
const DATABASE_PATH = `${VAR_FOLDER}/db.json`; | ||
|
||
module.exports = { | ||
DOWNLOADABLE_MIME_TYPES, | ||
RESOURCE, | ||
APPLICATION, | ||
DATABASE_PATH, | ||
VAR_FOLDER, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const mkdirp = require('mkdirp'); | ||
const low = require('lowdb'); | ||
const fs = require('fs'); | ||
const FileSync = require('lowdb/adapters/FileSync'); | ||
const logger = require('./logger'); | ||
const { DATABASE_PATH, VAR_FOLDER } = require('./config/config'); | ||
|
||
// use promisified fs | ||
const fsPromises = fs.promises; | ||
|
||
// bootstrap database | ||
const ensureDatabaseExists = async (dbPath = DATABASE_PATH) => { | ||
try { | ||
await fsPromises.readFile(dbPath, { encoding: 'utf8' }); | ||
} catch (readErr) { | ||
logger.error(readErr); | ||
try { | ||
mkdirp.sync(VAR_FOLDER); | ||
await fsPromises.writeFile(dbPath, ''); | ||
} catch (writeErr) { | ||
logger.error(writeErr); | ||
} | ||
} | ||
}; | ||
|
||
const bootstrapDatabase = (dbPath = DATABASE_PATH) => { | ||
const adapter = new FileSync(dbPath); | ||
const db = low(adapter); | ||
|
||
// set some defaults (required if json file is empty) | ||
db.defaults({ spaces: [] }).write(); | ||
return db; | ||
}; | ||
|
||
module.exports = { | ||
ensureDatabaseExists, | ||
bootstrapDatabase, | ||
}; |
Oops, something went wrong.