Skip to content

Commit

Permalink
fixbug: 401 Authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
ling-drag0n authored Dec 12, 2024
1 parent 0fcc68a commit bfd4359
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5197,10 +5197,22 @@ createApp({
const pathParts = window.location.pathname.split('/');
const id = pathParts[pathParts.length - 1];
// 构建请求头
const headers = {};
// 如果有密码,添加密码头
if (password.value) {
headers['X-Password'] = password.value;
}
// 如果是管理员,添加认证头
const credentials = localStorage.getItem('adminCredentials');
if (credentials) {
headers['Authorization'] = 'Basic ' + credentials;
}
const response = await fetch('/api/file/' + id + '?download=true', {
headers: password.value ? {
'X-Password': password.value
} : {}
headers: headers
});
if (!response.ok) {
Expand Down

0 comments on commit bfd4359

Please sign in to comment.