Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(ethereum: String, dappchain: String, plasmaAddress: String, privateKey: String) {
// If we're on node.js
let adapter
if (typeof localStorage === 'undefined' || localStorage === null) {
const low = require('lowdb')
adapter = new FileSync(`db/db_${privateKey}.json`)
} else {
adapter = new LocalStorage('db')
}
this.db = low(adapter)
// Initialize the database
this.db
.defaults({
ethereum: ethereum,
dappchain: dappchain,
plasma: plasmaAddress,
privatekey: privateKey,
coins: []
})
.write()
console.log('Initialized database', this.db.value())
}
public constructor() {
const adapter: Lowdb.AdapterSync = new FileSync(path.join(STORE_PATH, '/db.json'))
this.db = Lowdb(adapter)
// Use lodash-id must use insert methods
this.db._.mixin(LodashID)
if (!this.db.has('windowSize').value()) {
this.db
.set('windowSize', {
width: 1025,
height: 749,
})
.write()
}
if (!this.db.has('settings').value()) {
this.db
.set('settings', {
autoCheck: true,
currentLang: 'en',
public make(): void {
const adapterFile: string = `${process.env.CORE_PATH_CACHE}/webhooks.json`;
if (!existsSync(adapterFile)) {
ensureFileSync(adapterFile);
}
this.database = lowdb(new FileSync(adapterFile));
this.database.defaults({ webhooks: [] }).write();
}
NESTEDROUTEPREFIX: 'route:',
CONTENTTYPE: 'application/vnd.api+json',
ACCEPT: 'application/vnd.api+json',
};
process.env = {
...process.env,
...obj
};
}
export const globalContentType = process.env.CONTENTTYPE;
export const globalAccept = process.env.ACCEPT;
export const nestedRoutePrefix = process.env.NESTEDROUTEPREFIX;
export const json = JSON.parse(fs.readFileSync(process.env.WATCHFILE, 'utf8'));
export const port = process.env.PORT;
export const adapter = new FileSync(process.env.WATCHFILE);
export const db = low(adapter);
export const mainRoutes = [];
recursiveThroughRoutes(json, null, []);
import express from 'express';
import cors from 'cors';
import low from 'lowdb';
import uuid from 'uuid/v4';
import FileSync from 'lowdb/adapters/FileSync';
import { TodoItem, API } from '../common/types';
/**
* Setup db
*/
type DBSchema = {
items: TodoItem[]
}
const adapter = new FileSync('db.json', {
defaultValue: {
items: []
}
});
const db = low(adapter);
/**
* API server
*/
const app = express();
const api = express.Router();
api.use(cors(), express.json());
api.get(API.getAll.endpoint, (_, res) => {
res.send({ todos: db.get('items') });
});
private initDataStore(): void {
const settingAdapter = new FileSync(path.join(this.appDir, 'config/setting.json'))
const setting = low(settingAdapter)
this.$setting = setting
const postsAdapter = new FileSync(path.join(this.appDir, 'config/posts.json'))
const posts = low(postsAdapter)
this.$posts = posts
const themeAdapter = new FileSync(path.join(this.appDir, 'config/theme.json'))
const theme = low(themeAdapter)
this.$theme = theme
}
}
private initDataStore(): void {
const settingAdapter = new FileSync(path.join(this.appDir, 'config/setting.json'))
const setting = low(settingAdapter)
this.$setting = setting
const postsAdapter = new FileSync(path.join(this.appDir, 'config/posts.json'))
const posts = low(postsAdapter)
this.$posts = posts
const themeAdapter = new FileSync(path.join(this.appDir, 'config/theme.json'))
const theme = low(themeAdapter)
this.$theme = theme
}
}
loadShotsDb() {
const adapter = new FileSync('./server/database/projects.json');
const db = low(adapter);
return db;
}
}