ani-cli-npm
Version:
ani-cli tool rewritten as npm package
80 lines (78 loc) • 2.61 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.search_cache = exports.new_cache = exports.clear_cache = void 0;
const fs = __importStar(require("fs"));
function clear_cache(location, show) {
try {
console.log("ye sorry that doesnt exist yet.");
if (show) {
console.log("Cleared cache");
}
}
catch {
if (show) {
console.log("Failed to clear cache.");
}
}
}
exports.clear_cache = clear_cache;
function new_cache(location, anime) {
/*
Creates cache of Anime object, in cache file.
*/
try {
fs.writeFileSync(location + "/" + anime.id + ".cache", JSON.stringify(anime));
}
catch {
console.log("Failed to write to cache");
}
}
exports.new_cache = new_cache;
function get_cache(location, anime_id) {
/*
## Get cache by anime_id. Does not check if the cache exists.
*/
return JSON.parse(fs.readFileSync(location + "/" + anime_id + ".cache").toString());
}
function search_cache(cache_folder, anime_id) {
/*
## Searches cache folder for cache file with name of anime_id, at the location of cache_folder
### returns boolean for weather it is found.
*/
try {
if (check_cache(cache_folder, anime_id)) {
return get_cache(cache_folder, anime_id);
}
return false;
}
catch {
return false;
}
}
exports.search_cache = search_cache;
function check_cache(location, anime_id) {
return fs.readdirSync(location).includes(anime_id + ".cache");
}
;