-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create isResponseAvailability.mjs Update request.dev.js
- Loading branch information
1 parent
63039ad
commit 678d4c2
Showing
2 changed files
with
108 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { log } from "@nsnanocat/util"; | ||
|
||
/** | ||
* Determine Response Availability | ||
* @author VirgilClyne | ||
* @param {Object} response - Original Response Content | ||
* @return {Boolean} is Available | ||
*/ | ||
export default function isResponseAvailability(response = {}) { | ||
log("☑️ Determine Response Availability", ""); | ||
log(`statusCode: ${response.statusCode}`, `headers: ${JSON.stringify(response.headers)}`, ""); | ||
const FORMAT = (response?.headers?.["Content-Type"] ?? response?.headers?.["content-type"])?.split(";")?.[0]; | ||
log("🚧 Determine Response Availability", `FORMAT: ${FORMAT}`, ""); | ||
let isAvailable = true; | ||
switch (response?.statusCode) { | ||
case 200: | ||
switch (FORMAT) { | ||
case "application/grpc": | ||
case "application/grpc+proto": | ||
switch (response?.headers?.["Grpc-Message"] ?? response?.headers?.["grpc-message"]) { | ||
case "0": | ||
isAvailable = true; | ||
break; | ||
case undefined: | ||
case "": // 无内容 | ||
switch (response?.headers?.["content-length"] ?? response?.headers?.["content-length"]) { | ||
case undefined: | ||
isAvailable = true; | ||
break; | ||
default: | ||
if (Number.parseInt(response?.headers?.["content-length"] ?? response?.headers?.["Content-Length"]) < 1400) isAvailable = false; | ||
break; | ||
} | ||
break; | ||
case "-404": | ||
default: | ||
isAvailable = false; | ||
break; | ||
} | ||
break; | ||
case "text/json": | ||
case "application/json": | ||
switch (response?.headers?.["bili-status-code"]) { | ||
case "0": | ||
case undefined: { | ||
const data = JSON.parse(response?.body).data; | ||
switch (response?.headers?.idc) { | ||
case "sgp001": | ||
case "sgp002": | ||
switch (data?.limit) { | ||
case "": | ||
case undefined: | ||
isAvailable = true; | ||
break; | ||
default: | ||
isAvailable = false; | ||
break; | ||
} | ||
break; | ||
case "shjd": | ||
case undefined: | ||
default: | ||
switch (data?.video_info?.code) { | ||
case 0: | ||
default: | ||
isAvailable = true; | ||
break; | ||
case undefined: | ||
isAvailable = false; | ||
break; | ||
} | ||
switch (data?.dialog?.code) { | ||
case undefined: | ||
isAvailable = true; | ||
break; | ||
case 6010001: | ||
default: | ||
isAvailable = false; | ||
break; | ||
} | ||
break; | ||
} | ||
break; | ||
} | ||
case "-404": // 啥都木有 | ||
case "-10403": | ||
case "10015001": // 版权地区受限 | ||
default: | ||
isAvailable = false; | ||
break; | ||
} | ||
break; | ||
case "text/html": | ||
isAvailable = true; | ||
break; | ||
} | ||
break; | ||
case 403: | ||
case 404: | ||
case 415: | ||
default: | ||
isAvailable = false; | ||
break; | ||
} | ||
log("✅ Determine Response Availability", `isAvailable:${isAvailable}`, ""); | ||
return isAvailable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters