1
0

add alipan

This commit is contained in:
2024-02-02 17:18:44 +08:00
parent 7b9fc827ca
commit 33ac4f1250
12 changed files with 25400 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
#include "http.h"
#include "drive.h"
#include <qrcodegen/qrcodegen.h>
#include <fmt/format.h>
void printQr(const std::string& text) {
int border = 1;
@@ -10,16 +12,58 @@ void printQr(const std::string& text) {
for (int y = -border; y < width + border; y++) {
for (int x = -border; x < width + border; x++) {
qrcodegen_getModule(qrcode.data(), x, y) ? printf("\033[40m \033[0m") : printf("\033[47m \033[0m");
qrcodegen_getModule(qrcode.data(), x, y) ? fmt::print("\033[40m \033[0m")
: fmt::print("\033[47m \033[0m");
}
printf("\n");
fmt::print("\n");
}
printf("\n");
fmt::print("\n");
}
int main(int argc, char* argv[]) {
curl_global_init(CURL_GLOBAL_ALL);
drive::ref c = new_drive(dt_alipan);
if (!c->qrLogin(printQr)) return 1;
uint32_t choice = 0;
std::vector<std::string> stack = {"root"};
while (true) {
auto list = c->list(stack.back());
if (stack.size() > 1) {
fmt::print("0: 返回上一级\n");
}
for (size_t i = 0; i < list.size(); i++) {
fmt::print("{}: {}\n", i + 1, list[i].name);
}
fmt::print("{}: 创建目录\n", list.size() + 1);
fmt::print("{}: 上传文件\n", list.size() + 2);
fmt::print("选择文件或目录: \n");
scanf("%u", &choice);
if (choice > list.size() + 2 || choice < 0) {
break;
} else if (choice == 0 && stack.size() > 1) {
stack.pop_back();
} else if (choice == list.size() + 1) {
char name[1024];
fmt::print("请输入目录名: \n");
scanf("%s", name);
c->mkdir(stack.back(), name);
} else if (choice == list.size() + 2) {
char name[1024];
fmt::print("请输入文件名: \n");
scanf("%s", name);
c->upload(stack.back(), name);
} else if (list[choice - 1].folder) {
stack.push_back(list[choice - 1].id);
} else {
std::string link = c->link(list[choice - 1].id);
fmt::print("url: {}\n", link);
return 0;
}
}
curl_global_cleanup();
return 0;
}