-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22e8c8d
commit e3e179c
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: uploadDeckResourceCos | ||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [ main ] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
env: | ||
PACK_NAME: "" | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.11.0 | ||
cache: pip | ||
architecture: x64 | ||
- name: Run | ||
run: | | ||
cd ./script/ | ||
python -m pip install --upgrade pip | ||
python -m pip install -U cos-python-sdk-v5 | ||
python uploadDeckResourceCos.py ${{ secrets.EXTIVERSECOSSECRETID }} ${{ secrets.EXTIVERSECOSSECRETKEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from qcloud_cos import CosConfig | ||
from qcloud_cos import CosS3Client | ||
from qcloud_cos import CosServiceError | ||
from qcloud_cos import CosClientError | ||
import sys | ||
import logging | ||
import requests as req | ||
import os | ||
|
||
g_secret_id = '' | ||
g_secret_key = '' | ||
g_region = 'ap-shanghai' | ||
g_Bucket = 'extiverse-1253866028' | ||
|
||
if len(sys.argv) >= 2: | ||
g_secret_id = sys.argv[1] | ||
if len(sys.argv) >= 3: | ||
g_secret_key = sys.argv[2] | ||
|
||
def GETHttpFile(url, path): | ||
res = False | ||
send_url = url | ||
headers = {} | ||
try: | ||
msg_res = req.request("GET", send_url, headers = headers) | ||
with open(path, 'wb+') as tmp: | ||
tmp.write(msg_res.content) | ||
if msg_res.status_code in [200, 300]: | ||
res = True | ||
else: | ||
res = False | ||
except: | ||
res = False | ||
return res | ||
|
||
def upload(src, dst): | ||
global g_secret_id, g_secret_key, g_region, g_Bucket | ||
secret_id = g_secret_id | ||
secret_key = g_secret_key | ||
region = g_region | ||
token = None | ||
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) | ||
client = CosS3Client(config) | ||
object_key = dst | ||
with open(src, 'rb') as fp: | ||
response = client.put_object( | ||
Bucket=g_Bucket, | ||
Body=fp, | ||
Key=object_key, | ||
EnableMD5=True, | ||
StorageClass='STANDARD', | ||
ContentType='text/html; charset=utf-8' | ||
) | ||
print(response['ETag']) | ||
|
||
logging.basicConfig(level=logging.INFO, stream=sys.stdout) | ||
|
||
def file_name(file_dir): | ||
res = [] | ||
for root,dirs,files in os.walk(file_dir): | ||
for file in files: | ||
res.append(os.path.join(root.lstrip(file_dir), file)) | ||
return res | ||
|
||
if __name__ == '__main__': | ||
res = file_name('../deck/') | ||
for res_this in res: | ||
print(res_this) | ||
upload(os.path.join('..', 'deck', res_this), os.path.join('deck', res_this).replace('\\', '/')) |