From 7560e37ef4b904457e8542a4ff59b10c0908aa5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=B5=E8=BD=AE?= Date: Fri, 23 Sep 2022 16:48:05 +0800 Subject: [PATCH 1/3] Enable task mode --- src/s.yaml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/s.yaml b/src/s.yaml index 7efb461..7b593a8 100644 --- a/src/s.yaml +++ b/src/s.yaml @@ -15,7 +15,7 @@ # 更多函数计算案例,可参考:https://github.com/devsapp/awesome/ # 有问题快来钉钉群问一下吧:33947367 edition: 1.0.0 -name: UnZip OSS +name: UnZip OSS # access 是当前应用所需要的密钥信息配置: # 密钥配置可以参考:https://www.serverless-devs.com/serverless-devs/command/config # 密钥使用顺序可以参考:https://www.serverless-devs.com/serverless-devs/tool#密钥使用顺序与规范 @@ -35,7 +35,7 @@ services: role: "{{ roleArn }}" internetAccess: true function: - name: "{{ functionName }}" + name: "{{ functionName }}" handler: index.handler timeout: 7200 runtime: python3 @@ -44,6 +44,14 @@ services: environmentVariables: PROCESSED_DIR: "{{ processedDir }}" RETAIN_FILE_NAME: "{{ retainFileName }}" + # 如果是很大的 ZIP 文件, 想使用异步调用,可以开启如下配置, 将每次函数调用看做一个任务执行 + asyncConfiguration: + # destination: + # onSuccess: acs:fc:::services/${vars.service.name}/functions/dest-succ + # onFailure: acs:fc:::services/${vars.service.name}/functions/dest-fail + maxAsyncEventAgeInSeconds: 7200 + maxAsyncRetryAttempts: 3 + statefulInvocation: true triggers: - name: unzip-oss-trigger type: oss @@ -58,4 +66,4 @@ services: Key: Prefix: "{{ prefix }}" Suffix: .zip - bucketName: "{{ bucketName }}" \ No newline at end of file + bucketName: "{{ bucketName }}" From 6a69292a4a5d99c756854c5bedfe91d5ef0c7397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=B5=E8=BD=AE?= Date: Fri, 23 Sep 2022 16:50:57 +0800 Subject: [PATCH 2/3] Fallback to utf-8 when decode as gb18030 failed --- src/code/index.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/code/index.py b/src/code/index.py index 2f337c1..24b07a5 100644 --- a/src/code/index.py +++ b/src/code/index.py @@ -71,7 +71,10 @@ def get_zipfile_name(origin_name): # 解决中文乱码问题 except: name = name_bytes.decode(encoding="gb18030") else: - name = name_bytes.decode(encoding="gb18030") + try: + name = name_bytes.decode(encoding="gb18030") + except: + name = name_bytes.decode(encoding="utf-8") return name From 60ca66b39a556ef04a6586a2ff6303094c20565c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=B5=E8=BD=AE?= Date: Fri, 23 Sep 2022 16:51:19 +0800 Subject: [PATCH 3/3] Bump version --- publish.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/publish.yaml b/publish.yaml index 01900e6..2d86c48 100644 --- a/publish.yaml +++ b/publish.yaml @@ -1,6 +1,6 @@ Type: Application Name: start-unzip-oss -Version: 0.0.9 +Version: 0.0.10 Provider: - 阿里云 Description: 使用函数计算自动解压上传到OSS指定前缀目录的zip文件 @@ -67,8 +67,8 @@ Parameters: roleArn: title: RAM角色ARN type: string - default: '' - pattern: '^acs:ram::[0-9]*:role/.*$' + default: "" + pattern: "^acs:ram::[0-9]*:role/.*$" description: 应用所属的函数计算服务配置的 role, 请提前创建好对应的 role, 授信函数计算服务, 并配置好 AliyunOSSFullAccess 和 AliyunFCDefaultRolePolicy policy。 required: true x-role: @@ -106,8 +106,8 @@ Parameters: triggerRoleArn: title: 触发器RAM角色ARN type: string - default: '' - pattern: '^acs:ram::[0-9]*:role/.*$' + default: "" + pattern: "^acs:ram::[0-9]*:role/.*$" description: OSS使用此角色来发送事件通知来调用函数 required: true x-role: