|
|
@@ -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<std::string,bool> 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<module::tencent_cos>("fw_tencent_cos",
|