This app provides monitoring and information features for the common freifunk user and the technical stuff of a freifunk community.
Code base is taken from a TUM Practical Course project and added here to see if Freifunk Altdorf can use it.
https://www.freifunk-altdorf.de
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.6 KiB
77 lines
1.6 KiB
/** |
|
* Copyright (c) 2018-present, Facebook, Inc. |
|
* |
|
* This source code is licensed under the MIT license found in the |
|
* LICENSE file in the root directory of this source tree. |
|
* |
|
* @format |
|
* @flow |
|
*/ |
|
|
|
'use strict'; |
|
|
|
const fs = require('fs'); |
|
const mkdirp = require('mkdirp'); |
|
const path = require('path'); |
|
|
|
import type {TransformedCode} from 'metro/src/JSTransformer/worker'; |
|
|
|
export type Options = {| |
|
root: string, |
|
|}; |
|
|
|
const JOINER_DATA = '\0\0'; |
|
const JOINER_LIST = '\0'; |
|
|
|
class FileStore { |
|
_root: string; |
|
|
|
constructor(options: Options) { |
|
const root = options.root; |
|
|
|
for (let i = 0; i < 256; i++) { |
|
mkdirp.sync(path.join(root, ('0' + i.toString(16)).slice(-2))); |
|
} |
|
|
|
this._root = root; |
|
} |
|
|
|
get(key: Buffer): ?TransformedCode { |
|
try { |
|
const data = fs.readFileSync(this._getFilePath(key), 'utf8'); |
|
const [code, dependencies, map] = data.split(JOINER_DATA); |
|
|
|
return { |
|
code, |
|
dependencies: dependencies ? dependencies.split(JOINER_LIST) : [], |
|
map: JSON.parse(map), |
|
}; |
|
} catch (err) { |
|
if (err.code === 'ENOENT') { |
|
return null; |
|
} |
|
|
|
throw err; |
|
} |
|
} |
|
|
|
set(key: Buffer, value: TransformedCode): void { |
|
const data = [ |
|
value.code, |
|
value.dependencies.join(JOINER_LIST), |
|
JSON.stringify(value.map), |
|
].join(JOINER_DATA); |
|
|
|
fs.writeFileSync(this._getFilePath(key), data); |
|
} |
|
|
|
_getFilePath(key: Buffer): string { |
|
return path.join( |
|
this._root, |
|
key.slice(0, 1).toString('hex'), |
|
key.slice(1).toString('hex'), |
|
); |
|
} |
|
} |
|
|
|
module.exports = FileStore;
|
|
|