#include "http.h" #include "drive.h" #include #include void printQr(const std::string& text) { int border = 1; std::vector qrcode(qrcodegen_BUFFER_LEN_MAX), tmpbuf(qrcodegen_BUFFER_LEN_MAX); qrcodegen_encodeText(text.c_str(), tmpbuf.data(), qrcode.data(), qrcodegen_Ecc_LOW, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true); int width = qrcodegen_getSize(qrcode.data()); for (int y = -border; y < width + border; y++) { for (int x = -border; x < width + border; x++) { qrcodegen_getModule(qrcode.data(), x, y) ? fmt::print("\033[40m \033[0m") : fmt::print("\033[47m \033[0m"); } fmt::print("\n"); } fmt::print("\n"); } int main(int argc, char* argv[]) { curl_global_init(CURL_GLOBAL_ALL); auto c = drive::new_drive(drive::dt_alipan); if (!c->qrLogin(printQr)) return 1; uint32_t choice = 0; std::vector 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; }