fix: move cache to os.tmpdir() (#562)

* fix: move cache to os.tmpdir()

* revert snapshot
This commit is contained in:
shadyzoz 2020-06-18 23:25:45 +08:00 committed by GitHub
parent 78858bfb94
commit 8f3e54b1c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View File

@ -26,7 +26,7 @@ program
if (program.clear) {
require('../lib/certMgr').clearCerts(() => {
util.deleteFolderContentsRecursive(util.getAnyProxyPath('cache'));
util.deleteFolderContentsRecursive(util.getAnyProxyTmpPath());
console.log(color.green('done !'));
process.exit(0);
});

View File

@ -31,7 +31,7 @@ const WS_MESSAGE_FILE_PRFIX = 'ws_message_';
const CACHE_DIR_PREFIX = 'cache_r';
function getCacheDir() {
const rand = Math.floor(Math.random() * 1000000),
cachePath = path.join(proxyUtil.getAnyProxyPath('cache'), './' + CACHE_DIR_PREFIX + rand);
cachePath = path.join(proxyUtil.getAnyProxyTmpPath(), './' + CACHE_DIR_PREFIX + rand);
fs.mkdirSync(cachePath);
return cachePath;

View File

@ -5,7 +5,7 @@ const path = require('path');
const fs = require('fs');
const request = require('request');
const cachePath = proxyUtil.getAnyProxyPath('cache');
const cachePath = proxyUtil.getAnyProxyTmpPath();
/**
* download a file and cache

View File

@ -5,9 +5,11 @@ const fs = require('fs'),
mime = require('mime-types'),
color = require('colorful'),
child_process = require('child_process'),
os = require('os'),
Buffer = require('buffer').Buffer,
logUtil = require('./log');
const networkInterfaces = require('os').networkInterfaces();
const networkInterfaces = os.networkInterfaces();
// {"Content-Encoding":"gzip"} --> {"content-encoding":"gzip"}
module.exports.lower_keys = (obj) => {
@ -52,6 +54,14 @@ module.exports.getAnyProxyPath = function (pathName) {
return targetPath;
}
module.exports.getAnyProxyTmpPath = function () {
const targetPath = path.join(os.tmpdir(), 'anyproxy', 'cache');
if (!fs.existsSync(targetPath)) {
fs.mkdirSync(targetPath, { recursive: true });
}
return targetPath;
}
module.exports.simpleRender = function (str, object, regexp) {
return String(str).replace(regexp || (/\{\{([^{}]+)\}\}/g), (match, name) => {
if (match.charAt(0) === '\\') {