Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _initStorageSubSystem() {
await storage.init();
try {
const tmpIgnore = await storage.getItem('ignored');
this.Ignore = tmpIgnore || this.Ignore;
const tmpAdmins = await storage.getItem('admins');
if (tmpAdmins) {
this.Admins = tmpAdmins;
} else {
this.Admins = [_.toLower(this.Config.owner.nick)];
await storage.setItem('admins', this.Admins);
}
} catch (err) {
logger.error('Error Loading the Persisted Assets'); // TODO Localize
return;
}
logger.info(t('storage.initialized'));
}
export async function finishRegistration(jwt?: Accownt.JWT): Promise {
if (jwt === null) throw 'Invalid or expired token';
// Verify JWT's userId matches the userId that the JWT's email points to
// This way only the most recent email verification JWT is valid since it
// will point to the newest user
const userId = await emailToId(jwt.email);
if (userId != jwt.userId)
throw 'This token has been invalidated by a newer one';
// Verify user's email
await storage.init(STORAGE);
const user: Accownt.User = await storage.getItem(`user-${jwt.userId}`);
user.verified = true;
await storage.setItem(`user-${jwt.userId}`, user);
return await signJWT(jwt.userId, jwt.email, JWT_EXPIRES_IN);
}
async init() {
await storage.init({
dir: config.paths.storage,
stringify: JSON.stringify,
parse: JSON.parse,
encoding: 'utf8',
logging: false, // can also be custom logging function
continuous: true, // continously persist to disk
interval: false, // milliseconds, persist to disk on an interval
ttl: false, // ttl* [NEW], can be true for 24h default or a number in MILLISECONDS
expiredInterval: 7 * 24 * 3600 * 1000, // clear cache in 7 days
// in some cases, you (or some other service) might add non-valid storage files to your
// storage dir, i.e. Google Drive, make this true if you'd like to ignore these files and not throw an error
forgiveParseErrors: false // [NEW]
});
this.repositories = (await storage.getItem(this.key)) || [];
}
public static async persist(key: string, data: any) {
await storage.init();
await storage.setItem(key, data);
console.log(key);
console.log(data);
}
async function get_storage() {
if (cached_storage != null) {
return cached_storage
}
const storage = require('node-persist')
await storage.init()
//await storage.clear()
cached_storage = storage
return storage
}
async setupStore() {
await storage.init({
dir: 'store',
expiredInterval: 7200000,
});
}
async function getStorage() {
if (!storageInitialized) {
await _storage.init({
dir: path.join(os.homedir(), ".roblox-ts"),
});
storageInitialized = true;
}
return _storage;
}
vscode.commands.registerTextEditorCommand(Command.PasteTypeScriptAsTypesAndSerialization, editor =>
pasteAsTypes(editor, "typescript", false)
),
vscode.commands.registerTextEditorCommand(Command.OpenQuicktypeForJSON, editor =>
openForEditor(editor, "json")
),
vscode.commands.registerTextEditorCommand(Command.OpenQuicktypeForJSONSchema, editor =>
openForEditor(editor, "schema")
),
vscode.commands.registerTextEditorCommand(Command.OpenQuicktypeForTypeScript, editor =>
openForEditor(editor, "typescript")
),
vscode.commands.registerCommand(Command.ChangeTargetLanguage, changeTargetLanguage)
);
await persist.init({ dir: path.join(homedir(), ".quicktype-vscode") });
const maybeName = await persist.getItem(lastTargetLanguageUsedKey);
if (typeof maybeName === "string") {
explicitlySetTargetLanguage = languageNamed(maybeName);
}
}
public static async clear() {
await storage.init();
await storage.clear();
}
}