mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-06 16:20:09 +08:00
🚧 WIP(custom): v3.0.0 migrate to vite and esm
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
import crypto from 'crypto'
|
||||
import axios from 'axios'
|
||||
import { IStringKeyMap } from '#/types/types'
|
||||
|
||||
const AUTH_KEY_VALUE_RE = /(\w+)=["']?([^'"]{1,10000})["']?/
|
||||
let NC = 0
|
||||
const NC_PAD = '00000000'
|
||||
|
||||
function md5(text: crypto.BinaryLike) {
|
||||
return crypto.createHash('md5').update(text).digest('hex')
|
||||
function md5 (text: any) {
|
||||
return window.node.crypto.createHash('md5').update(text).digest('hex')
|
||||
}
|
||||
|
||||
export function digestAuthHeader(
|
||||
export function digestAuthHeader (
|
||||
method: string,
|
||||
uri: string,
|
||||
wwwAuthenticate: string,
|
||||
@@ -18,8 +17,8 @@ export function digestAuthHeader(
|
||||
) {
|
||||
const parts = wwwAuthenticate.split(',')
|
||||
const opts = {} as IStringKeyMap
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const m = AUTH_KEY_VALUE_RE.exec(parts[i])
|
||||
for (const i of parts) {
|
||||
const m = AUTH_KEY_VALUE_RE.exec(i)
|
||||
if (m) {
|
||||
opts[m[1]] = m[2].replace(/["']/g, '')
|
||||
}
|
||||
@@ -35,7 +34,7 @@ export function digestAuthHeader(
|
||||
|
||||
let nc = String(++NC)
|
||||
nc = NC_PAD.substring(nc.length) + nc
|
||||
const cnonce = crypto.randomBytes(8).toString('hex')
|
||||
const cnonce = window.node.crypto.randomBytes(8).toString('hex')
|
||||
|
||||
const ha1 = md5(userpassArray[0] + ':' + opts.realm + ':' + userpassArray[1])
|
||||
const ha2 = md5(method.toUpperCase() + ':' + uri)
|
||||
@@ -67,9 +66,9 @@ export function digestAuthHeader(
|
||||
return authstring
|
||||
}
|
||||
|
||||
export async function getAuthHeader(method: string, host: string, uri: string, username: string, password: string) {
|
||||
export async function getAuthHeader (method: string, host: string, uri: string, username: string, password: string) {
|
||||
try {
|
||||
await axios.get(`${host}${uri}`)
|
||||
await window.node.axios.get(`${host}${uri}`)
|
||||
} catch (error: any) {
|
||||
if (error.response.status === 401 && error.response.headers['www-authenticate']) {
|
||||
return digestAuthHeader(method, uri, error.response.headers['www-authenticate'], username, password)
|
||||
|
||||
Reference in New Issue
Block a user