@less-is-more/less-js 1.5.0-10 → 1.5.0-12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cache.js +11 -8
- package/src/nas.js +6 -2
package/package.json
CHANGED
package/src/cache.js
CHANGED
|
@@ -118,16 +118,19 @@ module.exports = class Cache {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
static _unzip(content) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
if (typeof content === "string") {
|
|
122
|
+
let text = "";
|
|
123
|
+
const buffer = Buffer.from(content, "base64");
|
|
124
|
+
// 判断是否gzip
|
|
125
|
+
if (buffer.length > 2 && buffer[0] === 0x1f && buffer[1] === 0x8b) {
|
|
126
|
+
text = zlib.gunzipSync(buffer).toString();
|
|
127
|
+
} else {
|
|
128
|
+
text = content;
|
|
129
|
+
}
|
|
130
|
+
return text;
|
|
127
131
|
} else {
|
|
128
|
-
|
|
132
|
+
return content;
|
|
129
133
|
}
|
|
130
|
-
return text;
|
|
131
134
|
}
|
|
132
135
|
|
|
133
136
|
static _needZip(text, zip) {
|
package/src/nas.js
CHANGED
|
@@ -140,7 +140,9 @@ class Nas {
|
|
|
140
140
|
|
|
141
141
|
try {
|
|
142
142
|
// 创建临时文件名,避免写入过程中的并发问题
|
|
143
|
-
const
|
|
143
|
+
const timestamp = Date.now();
|
|
144
|
+
const randomSuffix = Math.random().toFixed(4) * 10000;
|
|
145
|
+
const tempFilePath = `${filePath}.tmp.${timestamp}.${randomSuffix}`;
|
|
144
146
|
// 写入过期时间戳和值,用换行符分隔
|
|
145
147
|
const fileContent = `${expireTime}\n${content}`;
|
|
146
148
|
fs.writeFileSync(tempFilePath, fileContent, "utf8");
|
|
@@ -150,7 +152,9 @@ class Nas {
|
|
|
150
152
|
console.error("保存缓存文件失败:", filePath, e);
|
|
151
153
|
// 如果临时文件创建失败,清理临时文件
|
|
152
154
|
try {
|
|
153
|
-
fs.
|
|
155
|
+
if (fs.existsSync(tempFilePath)) {
|
|
156
|
+
fs.unlinkSync(tempFilePath);
|
|
157
|
+
}
|
|
154
158
|
} catch (cleanupError) {
|
|
155
159
|
// 忽略清理错误
|
|
156
160
|
}
|