mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-19 15:44:22 +00:00
fix: move cache to os.tmpdir() (#562)
* fix: move cache to os.tmpdir() * revert snapshot
This commit is contained in:
parent
78858bfb94
commit
8f3e54b1c5
@ -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);
|
||||
});
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
12
lib/util.js
12
lib/util.js
@ -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) === '\\') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user