remove ftp code

This commit is contained in:
ading2210 2024-03-19 16:40:25 -04:00
parent 6b32d503e2
commit d23703ff9a
4 changed files with 5 additions and 80 deletions

View file

@ -1,55 +0,0 @@
class FTPSession extends CurlSession {
constructor(url, options={}) {
if (!url.startsWith("ftp://") && !url.startsWith("ftps://")) {
throw "invalid url protocol";
}
super();
this.url = url;
this.options = options;
}
send_cmd(cmd) {
return new Promise((resolve, reject) => {
let request_ptr;
let chunks = [];
let data_callback = () => {};
let finish_callback = (error) => {
this.remove_request(request_ptr);
if (error) {
reject(`Sending FTP command failed with error ${error}: ${get_error_str(error)}`);
}
}
let headers_callback = (chunk) => {
chunks.push(chunk);
console.log(chunk);
}
request_ptr = this.create_request(this.url, data_callback, finish_callback, headers_callback);
c_func(_ftp_set_cmd, [request_ptr, cmd]);
});
}
download(path) {
let url = new URL(path, this.url).href;
console.log(url);
return new Promise((resolve, reject) => {
let request_ptr;
let finish_callback = (error) => {
this.remove_request(request_ptr);
if (error) {
reject(`FTP request failed with error ${error}: ${get_error_str(error)}`);
}
};
let headers_callback = (stream) => {
resolve(stream);
};
request_ptr = this.stream_response(url, headers_callback, finish_callback);
_ftp_set_options(request_ptr);
this.start_request(request_ptr);
});
}
}

View file

@ -102,7 +102,6 @@ api = {
CurlWebSocket: CurlWebSocket, CurlWebSocket: CurlWebSocket,
TLSSocket: TLSSocket, TLSSocket: TLSSocket,
HTTPSession: HTTPSession, HTTPSession: HTTPSession,
FTPSession: FTPSession,
fetch() {throw "not ready"}, fetch() {throw "not ready"},
get copyright() {return copyright_notice}, get copyright() {return copyright_notice},

View file

@ -79,7 +79,6 @@ class CurlSession {
this.event_loop = setInterval(() => { this.event_loop = setInterval(() => {
let libcurl_active = _session_get_active(this.session_ptr); let libcurl_active = _session_get_active(this.session_ptr);
if (libcurl_active || this.active_requests) { if (libcurl_active || this.active_requests) {
console.log("test");
_session_perform(this.session_ptr); _session_perform(this.session_ptr);
} }
else { else {
@ -147,12 +146,12 @@ class CurlSession {
headers_callback(stream); headers_callback(stream);
} }
if (error != 0) { console.log(error);
try {
stream_controller.close(); try {
} stream_controller.close();
catch {}
} }
catch {}
end_callback(error); end_callback(error);
} }

View file

@ -1,18 +0,0 @@
#include "curl/curl.h"
#include "types.h"
#include "util.h"
void ftp_set_options(CURL* easy_handle) {
curl_easy_setopt(easy_handle, CURLOPT_VERBOSE, 1L);
}
void ftp_set_cmd(CURL* easy_handle, const char* cmd) {
struct curl_slist *cmd_list = NULL;
cmd_list = curl_slist_append(cmd_list, cmd);
curl_easy_setopt(easy_handle, CURLOPT_QUOTE, cmd_list);
curl_easy_setopt(easy_handle, CURLOPT_NOBODY, 1L);
curl_slist_free_all(cmd_list);
}