From f3c5e012dbab69f93c2aa63e628ece07e4308087 Mon Sep 17 00:00:00 2001 From: 1585346868 <1585346868@qq.com> Date: Tue, 3 Mar 2026 18:46:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20src/tencent=5Fcos.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tencent_cos.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/tencent_cos.cpp b/src/tencent_cos.cpp index f17b7ff..904ea70 100644 --- a/src/tencent_cos.cpp +++ b/src/tencent_cos.cpp @@ -192,7 +192,67 @@ std::string module::tencent_cos::del(const std::string& appid,const std::string& cos_pool_destroy(p); return result; } +std::pair module::tencent_cos::exist(const std::string& appid,const std::string& endpoint,const std::string& access_key_id,const std::string& access_key_secret,const std::string& bucket_name,const std::string& object_name) +{ + int enable_checkpoint = COS_FALSE; // 是否开启断点续传 + cos_pool_t* p = NULL; + cos_string_t bucket; + cos_string_t object; + cos_string_t filename; + cos_status_t* s = NULL; + cos_table_t* headers = NULL; + cos_table_t* resp_headers = NULL; + cos_request_options_t* options = NULL; + cos_resumable_clt_params_t* clt_params; + cos_pool_create(&p, NULL); + + + + options = cos_request_options_create(p); + + options->config = cos_config_create(options->pool); + + cos_str_set(&options->config->endpoint, endpoint.c_str()); + cos_str_set(&options->config->access_key_id, access_key_id.c_str()); + cos_str_set(&options->config->access_key_secret, access_key_secret.c_str()); + cos_str_set(&options->config->appid, appid.c_str()); + // cos_str_set(&config->sts_token, token); // 使用临时密钥时的 token + options->config->is_cname = COS_FALSE; // 是否使用自定义域名 + + + options->ctl = cos_http_controller_create(options->pool, 0); + + + headers = cos_table_make(p, 0); + cos_str_set(&bucket, bucket_name.c_str()); + cos_str_set(&object, object_name.c_str()); + + + + cos_object_exist_status_e object_exist; + s = cos_check_object_exist(options, &bucket, &object, headers, &object_exist, &resp_headers); + + + std::string result = ""; + bool exist = false; + if (cos_status_is_ok(s)) { + result = ""; + if (object_exist == COS_OBJECT_NON_EXIST) { + exist = false; + } else if (object_exist == COS_OBJECT_EXIST) { + exist = true; + } else { + exist = false; + } + } + else + { + result = "code:" + std::to_string(s->code)+", error_code:"+s->error_code+", error_msg:"+s->error_msg; + } + cos_pool_destroy(p); + return {result,exist}; +} void module::tencent_cos::regist(sol::state* lua) { lua->new_usertype("fw_tencent_cos",