feat: 新增列表文件访问端点并兼容旧路径
服务器新增/list.txt接口提供列表文件访问,客户端优先请求该路径,失败时回退到原/uploads/list.txt路径
This commit is contained in:
@@ -82,6 +82,18 @@ app.use((req, res, next) => {
|
|||||||
else if (req.path.endsWith('.ts')) res.type('video/mp2t');
|
else if (req.path.endsWith('.ts')) res.type('video/mp2t');
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function sendListFile(res) {
|
||||||
|
if (!fs.existsSync(listFilePath)) {
|
||||||
|
return res.status(404).send('list.txt not found');
|
||||||
|
}
|
||||||
|
res.type('text/plain; charset=utf-8');
|
||||||
|
res.send(fs.readFileSync(listFilePath, 'utf8'));
|
||||||
|
}
|
||||||
|
|
||||||
|
app.get('/list.txt', (req, res) => sendListFile(res));
|
||||||
|
app.get('/uploads/list.txt', (req, res) => sendListFile(res));
|
||||||
|
|
||||||
app.use(express.static(path.join(__dirname, 'public')));
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
app.set('view engine', 'ejs');
|
app.set('view engine', 'ejs');
|
||||||
|
|
||||||
|
|||||||
@@ -1012,7 +1012,10 @@ end
|
|||||||
function Network.syncFiles()
|
function Network.syncFiles()
|
||||||
-- Sync only config file (list.txt) periodically
|
-- Sync only config file (list.txt) periodically
|
||||||
while true do
|
while true do
|
||||||
local resp = http.get(CONFIG.API_URL .. "/uploads/list.txt")
|
local resp = http.get(CONFIG.API_URL .. "/list.txt")
|
||||||
|
if not resp then
|
||||||
|
resp = http.get(CONFIG.API_URL .. "/uploads/list.txt")
|
||||||
|
end
|
||||||
if resp then
|
if resp then
|
||||||
local content = resp.readAll()
|
local content = resp.readAll()
|
||||||
resp.close()
|
resp.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user