Upload and extract function
Allows you to send a file to a file host, extract the download link and, if required, manage the manual deletion of the file.
π§ Function overviewβ
function upload_to_host(request_data, response_format, link_extraction = [], affix = [], manage_file = []) {
// ...
}
π¦ Parameters explainedβ
π request_data
β
The base configuration for the HTTP request to the host:
request_data[0]
β Endpoint URLrequest_data[1]
β HTTP method ("POST"
,"GET"
β¦)request_data[2]
β Body of the request (e.g. aFormData
object)request_data[3]
β Optional headers (e.g.{ "Content-Type": "application/json" }
)
π¬ response_format
β
Type of response expected from the server:
"json"
β if the server returns a JSON object"text"
β if the server returns plain text or HTML
π link_extraction
β
Rules to extract the download link from the serverβs response:
- πΉ Static:
["https://example.com/" + code]
β build the link manually - πΉ Regex match:
["match", /regex/, index]
β extract using a rege - πΉ Replace:
["replace", "&", "_"]
β replace characters in a string - πΉ JSON path:
["data", "downloadPage"]
β will returndata["data"]["downloadPage"]
π§© affix
β
Used to wrap the final link with a prefix and/or suffix:
affix[0]
β prefix (e.g."https://host.com/file/"
)affix[1]
β suffix (e.g.".html"
)
ποΈ manage_file
β
Used for hosts that allow deleting the uploaded file:
manage_file[0]
β Delete URL (string, regex, or nested JSON path)manage_file[1]
β HTTP method ("DELETE"
,"POST"
...)manage_file[2]
β Delete body contentmanage_file[3]
β [prefix, suffix] for delete URL
𧨠Special Case: Killcode Systemβ
Some hosts (like those using XFileSharing Pro) require an extra step with a killcode
before deletion. This is handled automatically:
if (manage_file[2][key][0] === "killcode") {
// Logic to extract the file ID
// Fetch the killcode page
// Extract killcode and optional token, code or/and rand
}
This allows deletion for hosts that use:
- Separate token-based deletion pages
- CSRF-protected forms
- Dynamic or time-based kill links
π§ͺ Examplesβ
β Example 1: JSON + Direct linkβ
upload_to_host(
[
"https://example.com/upload",
"POST",
formData,
{ Authorization: "Bearer token" }
],
"json",
["data", "url"]
);
β Example 2: Text + Regex matchβ
upload_to_host(
[
"https://example.com/upload",
"POST",
formData
],
"text",
["match", /https:\/\/example\.com\/file\/[a-z0-9]+/, 0]
);
β Example 3: Real case (Gofile)β
const sent_data_form = new FormData();
sent_data_form.append("file", STATE.file_to_upload);
const headers = api_key_host ? { "Authorization": "Bearer " + api_key_host } : {};
upload_to_host(
[
URL_FOR_BYPASS_CORS + "https://upload.gofile.io/uploadfile",
"POST",
sent_data_form,
headers
],
"json",
["data", "downloadPage"],
[],
api_key_host
? [
"https://api.gofile.io/contents",
"DELETE",
{
"contentsId": ["data", "parentFolder"]
},
[],
headers
]
: [
"https://api.gofile.io/contents",
"DELETE",
{
"contentsId":["data", "parentFolder"], "token": ["data", "guestToken"]
}
]
);