Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/anyproxy
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/ruleLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) === '\\') {
Expand Down