Skip to content

Commit 0ae1fe5

Browse files
committed
feat: prepare cos config for #13
1 parent 440c3e1 commit 0ae1fe5

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

app/Coding.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@ public function createUploadToken($token, $projectName, $fileName)
4646
'FileName' => $fileName,
4747
],
4848
]);
49-
return json_decode($response->getBody(), true)['Response']['Token'];
49+
$uploadToken = json_decode($response->getBody(), true)['Response']['Token'];
50+
preg_match_all(
51+
'|https://([a-z0-9\-]+)-(\d+)\.cos\.([a-z0-9\-]+)\.myqcloud\.com|',
52+
$uploadToken['UploadLink'],
53+
$matches
54+
);
55+
$uploadToken['Bucket'] = $matches[1][0];
56+
$uploadToken['AppId'] = $matches[2][0];
57+
$uploadToken['Region'] = $matches[3][0];
58+
return $uploadToken;
5059
}
5160

5261
public function createMarkdownZip($markdown, $path, $filename): bool|string

tests/Unit/CodingTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,18 @@ public function testCreateUploadToken()
7373
->willReturn(new Response(200, [], $responseBody));
7474
$coding = new Coding($clientMock);
7575
$result = $coding->createUploadToken($codingToken, $codingProjectUri, $fileName);
76-
$this->assertEquals(json_decode($responseBody, true)['Response']['Token'], $result);
76+
$this->assertEquals([
77+
'AuthToken' => '65e5968b5e17d5aaa3f5d33200aca2d1911fe2ad2948b47d899d46e6da1e4',
78+
'Provide' => 'TENCENT',
79+
'SecretId' => 'AKIDU-VqQm39vRar-ZrHj1UIE5u2gYJ7gWFcG2ThwFNO9eU1HbyQlZp8vVcQ99',
80+
'SecretKey' => 'clUYSNeg2es16EILsrF6RyCD3ss6uFLX3Xgc=',
81+
'UploadLink' => 'https://coding-net-dev-file-123456.cos.ap-shanghai.myqcloud.com',
82+
'UpToken' => 'EOlMEc2x0xbrFoL9CMy7OqDl5413654938410a360a63207e30dab4655pMKmNJ3t5M-Z8bGt',
83+
'Time' => 1625579588693,
84+
'Bucket' => 'coding-net-dev-file',
85+
'AppId' => '123456',
86+
'Region' => 'ap-shanghai',
87+
], $result);
7788
}
7889

7990
public function testCreateMarkdownZip()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Hello World!
2+
3+
第一章
4+
---
5+
6+
hello
7+
8+
### 1.1 What is Lorem Ipsum?
9+
10+
**Lorem Ipsum** is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
11+
12+
### 1.2 Why do we use it?
13+
14+
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
15+
16+
![](attachments/65619/65624.png)
17+
18+
第二章
19+
---
20+
21+
world
22+
23+
![](attachments/65619/65623.png)

0 commit comments

Comments
 (0)