creating cache directories
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
SITE_COOKIES,
|
SITE_COOKIES,
|
||||||
} from '../util/Constants';
|
} from '../util/Constants';
|
||||||
import Selectors from '../util/Selectors';
|
import Selectors from '../util/Selectors';
|
||||||
|
import { createCacheDirectories } from '../util/TempDirCreator';
|
||||||
|
|
||||||
class CookieMonster {
|
class CookieMonster {
|
||||||
cache;
|
cache;
|
||||||
@@ -14,6 +15,7 @@ class CookieMonster {
|
|||||||
|
|
||||||
constructor(cache) {
|
constructor(cache) {
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
|
createCacheDirectories(TEMP_DIR.screenshots);
|
||||||
}
|
}
|
||||||
|
|
||||||
async submitForm(plate) {
|
async submitForm(plate) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import Cacheman from 'cacheman';
|
import Cacheman from 'cacheman';
|
||||||
import { CACHE } from './Constants';
|
import { CACHE } from './Constants';
|
||||||
|
import { createCacheDirectories } from './TempDirCreator';
|
||||||
|
|
||||||
const formatKey = (name) => {
|
const formatKey = (name) => {
|
||||||
if (!name) {
|
if (!name) {
|
||||||
@@ -12,6 +13,7 @@ class Cache {
|
|||||||
manager;
|
manager;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
createCacheDirectories(CACHE.directory);
|
||||||
this.manager = new Cacheman({
|
this.manager = new Cacheman({
|
||||||
ttl: CACHE.ttl,
|
ttl: CACHE.ttl,
|
||||||
engine: CACHE.engine,
|
engine: CACHE.engine,
|
||||||
|
|||||||
15
api/src/util/TempDirCreator.js
Normal file
15
api/src/util/TempDirCreator.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
|
/* eslint-disable import/prefer-default-export */
|
||||||
|
|
||||||
|
export const createCacheDirectories = async (targetDir) => {
|
||||||
|
if (!fs.existsSync(targetDir)) {
|
||||||
|
console.log(`Directory ${targetDir} does not exist. Creating it.`);
|
||||||
|
fs.mkdirSync(targetDir, {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log(`Directory ${targetDir} already exists.`);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user