Skip to content

Commit 8c52f4d

Browse files
committed
fix: 修复vercel无文件创建权限问题 #1796
1 parent 52c6021 commit 8c52f4d

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

CHANGELOG.MD

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# 更新日志
2+
### 4.11.2 | 2023.09.09
3+
- 修复`vercel`无文件创建权限问题
4+
25
### 4.11.1 | 2023.09.08
36
- `anonymous_token` 配置抽离
47

app.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env node
22
const fs = require('fs')
33
const path = require('path')
4+
const tmpPath = require('os').tmpdir()
45

56
async function start() {
67
// 检测是否存在 anonymous_token 文件,没有则生成
7-
if (!fs.existsSync('./anonymous_token')) {
8-
fs.writeFileSync(path.resolve(__dirname, 'anonymous_token'), '', 'utf-8')
8+
if (!fs.existsSync(path.resolve(tmpPath, 'anonymous_token'))) {
9+
fs.writeFileSync(path.resolve(tmpPath, 'anonymous_token'), '', 'utf-8')
910
}
1011
const generateConfig = require('./generateConfig')
1112
await generateConfig()

generateConfig.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
const fs = require('fs')
2+
const path = require('path')
23
const { register_anonimous } = require('./main')
34
const { cookieToJson } = require('./util/index')
4-
const path = require('path')
5+
6+
const tmpPath = require('os').tmpdir()
57
async function generateConfig() {
68
try {
79
const res = await register_anonimous()
810
const cookie = res.body.cookie
911
if (cookie) {
1012
const cookieObj = cookieToJson(cookie)
1113
fs.writeFileSync(
12-
path.resolve(__dirname, 'anonymous_token'),
14+
path.resolve(tmpPath, 'anonymous_token'),
1315
cookieObj.MUSIC_A,
1416
'utf-8',
1517
)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "NeteaseCloudMusicApi",
3-
"version": "4.11.1",
3+
"version": "4.11.2",
44
"description": "网易云音乐 NodeJS 版 API",
55
"scripts": {
66
"start": "node app.js",

util/request.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ const http = require('http')
66
const https = require('https')
77
const tunnel = require('tunnel')
88
const fs = require('fs')
9-
const anonymous_token = fs.readFileSync('./anonymous_token', 'utf-8')
9+
const path = require('path')
10+
const tmpPath = require('os').tmpdir()
11+
const anonymous_token = fs.readFileSync(
12+
path.resolve(tmpPath, './anonymous_token'),
13+
'utf-8',
14+
)
1015
console.log(anonymous_token)
1116
const { URLSearchParams, URL } = require('url')
1217
// request.debug = true // 开启可看到更详细信息

0 commit comments

Comments
 (0)