first commit
This commit is contained in:
commit
abb2b74468
8 files changed
+122
No files matched your search
@@ -0,0 +1,2 @@
|
||||
/.idea/
|
||||
./.gitignore
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 已忽略包含查询文件的默认文件夹
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
Generated
+5
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/TurboWarp_S3.iml" filepath="$PROJECT_DIR$/TurboWarp_S3.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="GENERAL_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
(function (Scratch) {
|
||||
'use strict';
|
||||
|
||||
// 非沙箱守卫:确保扩展有权限发起网络请求
|
||||
if (!Scratch.extensions.unsandboxed) {
|
||||
throw new Error('S3 扩展必须运行在非沙箱模式下');
|
||||
}
|
||||
|
||||
class S3Extension {
|
||||
constructor() {
|
||||
// 在内存中保存凭据(仅用于演示,生产环境需注意安全)
|
||||
this.credentials = {};
|
||||
}
|
||||
|
||||
getInfo() {
|
||||
return {
|
||||
id: 's3client',
|
||||
name: 'S3 客户端',
|
||||
blocks: [
|
||||
{
|
||||
opcode: 'setCredentials',
|
||||
blockType: Scratch.BlockType.COMMAND,
|
||||
text: '设置 S3 凭据 Key [AK] Secret [SK] 区域 [REGION]',
|
||||
arguments: {
|
||||
AK: { type: Scratch.ArgumentType.STRING, defaultValue: 'AKIA...' },
|
||||
SK: { type: Scratch.ArgumentType.STRING, defaultValue: 'secret...' },
|
||||
REGION: { type: Scratch.ArgumentType.STRING, defaultValue: 'us-east-1' }
|
||||
}
|
||||
},
|
||||
{
|
||||
opcode: 'putObject',
|
||||
blockType: Scratch.BlockType.COMMAND,
|
||||
text: '上传桶 [BUCKET] 键 [KEY] 内容 [BODY]',
|
||||
arguments: {
|
||||
BUCKET: { type: Scratch.ArgumentType.STRING, defaultValue: 'my-bucket' },
|
||||
KEY: { type: Scratch.ArgumentType.STRING, defaultValue: 'hello.txt' },
|
||||
BODY: { type: Scratch.ArgumentType.STRING, defaultValue: 'Hello S3!' }
|
||||
}
|
||||
},
|
||||
{
|
||||
opcode: 'getObject',
|
||||
blockType: Scratch.BlockType.REPORTER,
|
||||
text: '下载桶 [BUCKET] 键 [KEY]',
|
||||
arguments: {
|
||||
BUCKET: { type: Scratch.ArgumentType.STRING, defaultValue: 'my-bucket' },
|
||||
KEY: { type: Scratch.ArgumentType.STRING, defaultValue: 'hello.txt' }
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
setCredentials(args) {
|
||||
this.credentials = {
|
||||
accessKey: args.AK,
|
||||
secretKey: args.SK,
|
||||
region: args.REGION
|
||||
};
|
||||
}
|
||||
|
||||
// 这里接入上一轮实现的 SigV4 签名与 fetch 调用
|
||||
async putObject(args) {
|
||||
const { accessKey, secretKey, region } = this.credentials;
|
||||
// 1. 计算 payload hash(对 BODY 做 SHA256)
|
||||
// 2. 构造 CanonicalRequest -> StringToSign -> Signature
|
||||
// 3. fetch(`https://${args.BUCKET}.s3.${region}.amazonaws.com/${args.KEY}`, { method: 'PUT', ... })
|
||||
// 返回成功或抛出错误
|
||||
}
|
||||
|
||||
async getObject(args) {
|
||||
// 签名时 payload hash 为空字符串的 SHA256
|
||||
// fetch GET,返回 res.text() 或 arrayBuffer
|
||||
}
|
||||
}
|
||||
|
||||
Scratch.extensions.register(new S3Extension());
|
||||
})(Scratch);
|
||||
Reference in new issue
Block a user