@crawlee/utils
Advanced tools
Comparing version 3.0.0-alpha.49 to 3.0.0-alpha.50
@@ -46,11 +46,2 @@ /// <reference types="node" /> | ||
/** | ||
* Cleans up the default local storage directories before the run starts: | ||
* - local directory containing the default dataset; | ||
* - all records from the default key-value store in the local directory, except for the "INPUT" key; | ||
* - local directory containing the default request queue. | ||
* | ||
* @param [folder] The folder to clean up | ||
*/ | ||
export declare function purgeLocalStorage(folder?: string): Promise<void>; | ||
/** | ||
* Gets parsed content type from response object | ||
@@ -57,0 +48,0 @@ * @param response HTTP response object |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseContentTypeFromResponse = exports.purgeLocalStorage = exports.snakeCaseToCamelCase = exports.sleep = exports.weightedAvg = exports.isDocker = exports.URL_WITH_COMMAS_REGEX = exports.URL_NO_COMMAS_REGEX = void 0; | ||
exports.parseContentTypeFromResponse = exports.snakeCaseToCamelCase = exports.sleep = exports.weightedAvg = exports.isDocker = exports.URL_WITH_COMMAS_REGEX = exports.URL_NO_COMMAS_REGEX = void 0; | ||
const tslib_1 = require("tslib"); | ||
const consts_1 = require("@apify/consts"); | ||
const content_type_1 = tslib_1.__importDefault(require("content-type")); | ||
@@ -12,3 +11,2 @@ const mime_types_1 = tslib_1.__importDefault(require("mime-types")); | ||
const node_url_1 = require("node:url"); | ||
const fs_extra_1 = require("fs-extra"); | ||
const ow_1 = tslib_1.__importDefault(require("ow")); | ||
@@ -96,36 +94,2 @@ /** | ||
/** | ||
* Cleans up the default local storage directories before the run starts: | ||
* - local directory containing the default dataset; | ||
* - all records from the default key-value store in the local directory, except for the "INPUT" key; | ||
* - local directory containing the default request queue. | ||
* | ||
* @param [folder] The folder to clean up | ||
*/ | ||
async function purgeLocalStorage(folder) { | ||
// If the user did not provide a folder, try to get it from the env variables, or the default one | ||
if (!folder) | ||
folder = process.env[consts_1.ENV_VARS.LOCAL_STORAGE_DIR] || 'apify_storage'; | ||
const defaultDatasetPath = node_path_1.default.resolve(folder, consts_1.LOCAL_STORAGE_SUBDIRS.datasets, consts_1.LOCAL_ENV_VARS[consts_1.ENV_VARS.DEFAULT_DATASET_ID]); | ||
await removeFiles(defaultDatasetPath); | ||
const defaultKeyValueStorePath = node_path_1.default.resolve(folder, consts_1.LOCAL_STORAGE_SUBDIRS.keyValueStores, consts_1.LOCAL_ENV_VARS[consts_1.ENV_VARS.DEFAULT_KEY_VALUE_STORE_ID]); | ||
await removeFiles(defaultKeyValueStorePath); | ||
const defaultRequestQueuePath = node_path_1.default.resolve(folder, consts_1.LOCAL_STORAGE_SUBDIRS.requestQueues, consts_1.LOCAL_ENV_VARS[consts_1.ENV_VARS.DEFAULT_REQUEST_QUEUE_ID]); | ||
await removeFiles(defaultRequestQueuePath); | ||
} | ||
exports.purgeLocalStorage = purgeLocalStorage; | ||
async function removeFiles(folder) { | ||
const storagePathExists = await (0, fs_extra_1.pathExists)(folder); | ||
if (storagePathExists) { | ||
const direntNames = await promises_1.default.readdir(folder); | ||
const deletePromises = []; | ||
for (const direntName of direntNames) { | ||
const fileName = node_path_1.default.join(folder, direntName); | ||
if (!RegExp(consts_1.KEY_VALUE_STORE_KEYS.INPUT).test(fileName)) { | ||
deletePromises.push(promises_1.default.rm(fileName, { recursive: true, force: true })); | ||
} | ||
} | ||
await Promise.all(deletePromises); | ||
} | ||
} | ||
/** | ||
* Gets parsed content type from response object | ||
@@ -132,0 +96,0 @@ * @param response HTTP response object |
{ | ||
"name": "@crawlee/utils", | ||
"version": "3.0.0-alpha.49", | ||
"version": "3.0.0-alpha.50", | ||
"description": "A set of shared utilities that can be used by crawlers", | ||
@@ -5,0 +5,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
182001
1759