1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 
5 #include "oss_app.h"
6 #include "py/builtin.h"
7 #include "py/mperrno.h"
8 #include "py/obj.h"
9 #include "py/runtime.h"
10 #include "ulog/ulog.h"
11 
12 #define LOG_TAG "MOD_OSS"
13 
obj_uploadFile(size_t n_args,const mp_obj_t * args)14 STATIC mp_obj_t obj_uploadFile(size_t n_args, const mp_obj_t *args)
15 {
16     LOGD(LOG_TAG, "entern  %s; n_args = %d;\n", __func__, n_args);
17     int ret = -1;
18     char *url = NULL;
19     if (n_args < 5) {
20         LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__,
21              n_args);
22         return mp_const_none;
23     }
24 
25     char *key = (char *)mp_obj_str_get_str(args[0]);
26     char *secret = (char *)mp_obj_str_get_str(args[1]);
27     char *endPoint = (char *)mp_obj_str_get_str(args[2]);
28     char *bucketName = (char *)mp_obj_str_get_str(args[3]);
29     char *filePath = (char *)mp_obj_str_get_str(args[4]);
30     LOGD(LOG_TAG, "key = %s;\n", key);
31     LOGD(LOG_TAG, "secret = %s;\n", secret);
32     LOGD(LOG_TAG, "endPoint = %s;\n", endPoint);
33     LOGD(LOG_TAG, "bucketName = %s;\n", bucketName);
34     LOGD(LOG_TAG, "filePath = %s;\n", filePath);
35     url = oss_upload_local_file(key, secret, endPoint, bucketName, filePath);
36 
37     return mp_obj_new_strn(url);
38 }
39 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(oss_obj_uploadFile, 5, obj_uploadFile);
40 
obj_uploadContent(size_t n_args,const mp_obj_t * args)41 STATIC mp_obj_t obj_uploadContent(size_t n_args, const mp_obj_t *args)
42 {
43     LOGD(LOG_TAG, "entern  %s; n_args = %d;\n", __func__, n_args);
44     int ret = -1;
45     char *url = NULL;
46     if (n_args < 5) {
47         LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__,
48              n_args);
49         return mp_const_none;
50     }
51 
52     char *key = (char *)mp_obj_str_get_str(args[0]);
53     char *secret = (char *)mp_obj_str_get_str(args[1]);
54     char *endPoint = (char *)mp_obj_str_get_str(args[2]);
55     char *bucketName = (char *)mp_obj_str_get_str(args[3]);
56     char *fileContent = (char *)mp_obj_str_get_str(args[4]);
57     LOGD(LOG_TAG, "key = %s;\n", key);
58     LOGD(LOG_TAG, "secret = %s;\n", secret);
59     LOGD(LOG_TAG, "endPoint = %s;\n", endPoint);
60     LOGD(LOG_TAG, "bucketName = %s;\n", bucketName);
61     LOGD(LOG_TAG, "fileContent = %s;\n", fileContent);
62     url = oss_upload_local_content(key, secret, endPoint, bucketName,
63                                    fileContent);
64 
65     return mp_obj_new_strn(url);
66 }
67 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(oss_obj_uploadContent, 5, obj_uploadContent);
68 
69 STATIC const mp_rom_map_elem_t oss_locals_dict_table[] = {
70     { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_OSS) },
71     { MP_ROM_QSTR(MP_QSTR_uploadFile), MP_ROM_PTR(&oss_obj_uploadFile) },
72     { MP_ROM_QSTR(MP_QSTR_uploadContent), MP_ROM_PTR(&oss_obj_uploadContent) },
73 };
74 
75 STATIC MP_DEFINE_CONST_DICT(oss_locals_dict, oss_locals_dict_table);
76 
77 const mp_obj_module_t oss_module = {
78     .base = { &mp_type_module },
79     .globals = (mp_obj_dict_t *)&oss_locals_dict,
80 };
81