Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const fileToKey = (data, storyId) => {
const { name, type } = data;
// console.log(name, type);
let namespace = storyId;
if (namespace.indexOf("_")) namespace = namespace.split("_").pop();
if (namespace.length < 36) namespace = shortUuid().toUUID(namespace);
const uuid = uuidv5(`${type},${name}`, namespace);
return `${shortUuid().fromUUID(uuid)}-${name}`;
};
const fileToKey = (data, storyId) => {
const { name, type } = data;
// console.log(name, type);
let namespace = storyId;
if (namespace.indexOf("_")) namespace = namespace.split("_").pop();
if (namespace.length < 36) namespace = shortUuid().toUUID(namespace);
const uuid = uuidv5(`${type},${name}`, namespace);
return `${shortUuid().fromUUID(uuid)}-${name}`;
};
updateDownload(path, delta = 1) {
let id = uuid(path, UUID_NAMESPACE);
return this.db
.get(id)
.then(data => {
data.downloads += delta;
return this.db.put(id, data);
})
.then(retVal => {
// We also need to update parent's download value.
// NOTE: If this is might cause perfomance problems.
let parentPath = Path.dirname(path);
this.db
.get(uuid(parentPath, UUID_NAMESPACE))
.then(() => {
this.update(parentPath);
})
async update(path) {
try {
let stat = await fstat(path);
let name = Path.basename(path);
let downloads = 0;
let description = "";
let tags = [];
let type = "file";
let id = uuid(path, UUID_NAMESPACE);
let size = stat.size;
try {
// Extract old values if they exist
({ downloads, tags, description } = await this.db.get(id));
} catch (err) {
// If error occured for a reason other than key not being
// present then rethrow error
if (!err.notFound) throw err;
}
// Set downloads value to max of children if directory and also
// Calculate size of directory
if (stat.isDirectory()) {
type = "dir";
size = 0;
const computeId = (userId, storyId) => {
let namespace = userId;
if (namespace.indexOf(":") > 0) namespace = namespace.split(":").pop();
let id = storyId;
if (id.indexOf("_")) id = id.split("_").pop();
if (id.length < 36) id = shortUuid().toUUID(id);
const uuid = uuidv5(id, namespace);
return shortUuid().fromUUID(uuid);
};
const createNodeId = id =>
uuidv5(id, uuidv5('gatsby-source-prismic', seedConstant))
const createContentDigest = obj => md5(JSON.stringify(obj))
getDataFromPath(path) {
return this.db.get(uuid(path, UUID_NAMESPACE));
}