Browse Source

首次提交

a158 9 months ago
parent
commit
ea6f94e9ff

BIN
3rdparty/apr-1.7.6.tar.gz


BIN
3rdparty/apr-util-1.6.3.tar.gz


BIN
3rdparty/cos-c-sdk-v5-master.zip


BIN
3rdparty/cos-cpp-sdk-v5-5.5.19.zip


BIN
3rdparty/mxml-4.0.4.zip


BIN
3rdparty/poco-poco-1.12.4-release.zip


+ 36 - 19
build.sh

@@ -2,32 +2,49 @@
 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
 cd "$SCRIPT_DIR"
 
-# 安装阿里云核心
-mkdir tmp
-cd tmp
-git clone https://gitee.com/yobonianhua/aliyun-openapi-cpp-sdk.git
-cd aliyun-openapi-cpp-sdk
-sudo sh easyinstall.sh core
-cd ${SCRIPT_DIR}
-
-# 安装阿里云OSS
-sudo apt-get install libcurl4-openssl-dev libapr1-dev libaprutil1-dev libmxml-dev -y
+# Install APR
 cd 3rdparty
-rm -rf aliyun-oss-c-sdk-3.11.2
-unzip aliyun-oss-c-sdk-3.11.2.zip
-cd aliyun-oss-c-sdk-3.11.2
-mkdir build
-cd build
-cmake ..
+rm -rf apr-1.7.6
+tar -zxvf apr-1.7.6.tar.gz
+cd apr-1.7.6
+./configure
 make
 make install
-cd ${SCRIPT_DIR}
 
 
-# 安装ALIYUN
+
+# Install APR-UTIL
+cd "$SCRIPT_DIR/3rdparty"
+rm -rf apr-util-1.6.3
+tar -zxvf apr-util-1.6.3.tar.gz
+cd apr-util-1.6.3
+./configure --with-path=/usr
+make
+make install
+
+# Install mxml-4.0.4.zip
+cd "$SCRIPT_DIR/3rdparty"
+rm -rf mxml-4.0.4
+unzip mxml-4.0.4.zip
+cd mxml-4.0.4
+./configure
+make
+make install
+
+# 编译 SDK
+cd "$SCRIPT_DIR/3rdparty"
+rm -rf cos-c-sdk-v5-master
+unzip cos-c-sdk-v5-master.zip
+cd cos-c-sdk-v5-master
+cmake .
+make
+make install
+
+# 安装
+cd "$SCRIPT_DIR"
 rm -rf build
 mkdir build
 cd build
 cmake ..
 make
-cp -f libaliyunsdk.so ../target
+cp -f libtencent_cos_sdk.so ../target

+ 95 - 0
src/tencent_cos.cpp

@@ -0,0 +1,95 @@
+#include "tencent_cos.h"
+#include "dll_interface.h"
+#include "cos_api.h"
+#include "cos_http_io.h"
+#include "cos_log.h"
+extern "C" {
+#ifdef _WIN32
+    DLL_EXPORT
+#endif
+        int fastweb_module_regist(void* sol2, void* lua)
+    {
+        sol::state* state = static_cast<sol::state*>(sol2);
+        module::tencent_cos::regist(state);
+        return 0;
+    }
+}
+
+module::tencent_cos::tencent_cos()
+{
+    if (cos_http_io_initialize(NULL, 0) != COSE_OK) {
+        printf("COS HTTP INIT FAILED");
+    }
+}
+
+module::tencent_cos::~tencent_cos()
+{
+    cos_http_io_deinitialize();
+}
+
+std::string module::tencent_cos::upfile(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,const std::string& filepath)
+{
+
+    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_str_set(&filename, filepath.c_str());
+    // upload
+    clt_params = cos_create_resumable_clt_params_content(p, 1024 * 1024 * 5, 8, enable_checkpoint, NULL);
+    s = cos_resumable_upload_file(options, &bucket, &object, &filename, headers, NULL,
+                                  clt_params, NULL, &resp_headers, NULL);
+    
+    std::string result = "";
+    if (cos_status_is_ok(s)) {
+        result = "";
+    }
+    else
+    {
+        result = "code:" + std::to_string(s->code)+", error_code:"+s->error_code+", error_msg:"+s->error_msg;
+    }
+    cos_pool_destroy(p);
+    return result;
+}
+
+void module::tencent_cos::regist(sol::state* lua)
+{
+    lua->new_usertype<module::tencent_cos>("fw_tencent_cos",
+        "new", sol::constructors<module::tencent_cos()>(),
+        "upfile", &module::tencent_cos::upfile
+    );
+}
+
+void module::tencent_cos::regist_global(const char* name, sol::state* lua)
+{
+    lua->registry()[name] = this;
+    (*lua)[name] = this;
+}

+ 18 - 0
src/tencent_cos.h

@@ -0,0 +1,18 @@
+#pragma once
+#include "basemodule.h"
+namespace module
+{
+	class tencent_cos : public module::base {
+	public:
+		tencent_cos();
+		~tencent_cos() override;
+		std::string upfile(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,const std::string& filename);
+
+		static void regist(sol::state* lua);
+	private:
+		// 通过 imodule 继承
+		virtual void regist_global(const char* name, sol::state* lua);
+		virtual void delete_global() { delete this; }
+	};
+}
+

+ 27 - 0
target/tencent_cos.lua

@@ -0,0 +1,27 @@
+local tencent_cos = {}
+tencent_cos.__index = tencent_cos
+
+--[[
+    创建一个新的 tencent_cos 对象
+    @return 返回一个新的 tencent_cos 对象
+]]
+function tencent_cos.new(db)
+    local instance = setmetatable({}, tencent_cos)
+    if db == nil then
+        instance.module = fw_tencent_cos.new()
+    else
+        instance.module = db    
+    end
+    
+    return instance
+end
+
+
+function tencent_cos:upfile(appid,endpoint,access_key_id, access_key_secret,bucket_name,object_name,filename)
+    return self.module:upfile(appid,endpoint,access_key_id, access_key_secret,bucket_name,object_name,filename)
+end
+function tencent_cos:self()
+    return self.module:self()
+end
+
+return tencent_cos