Skip to content

Commit d5fc5ff

Browse files
Merge pull request #9 from waifuvault/1.0.5-dev
chore: moved the password field from URI param to body param
2 parents e494176 + 25a08ec commit d5fc5ff

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

src/WaifuApi.php

+10-16
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,16 @@
1313
*
1414
* @link https://waifuvault.moe/
1515
*
16-
* @phpstan-type FileUpload array{
17-
* file: string,
18-
* filename?: string
19-
* }
20-
* @phpstan-type FileContentUpload array{
21-
* file_contents: string,
22-
* filename: string
23-
* }
24-
* @phpstan-type UrlUpload array{
25-
* url: string
26-
* }
27-
*
2816
* @phpstan-type uploadFileArg array{
17+
* file?: string,
18+
* url?: string,
19+
* filename?: string,
20+
* file_contents?: string,
2921
* expires?:string,
3022
* hide_filename?:bool,
3123
* password?:string,
3224
* one_time_download?:bool
33-
* }&(FileUpload|FileContentUpload|UrlUpload)
25+
* }
3426
*
3527
* @phpstan-type modifyFileArg array{
3628
* token: string,
@@ -69,7 +61,6 @@ function ($v, $k) {
6961
return in_array($k, array(
7062
'expires',
7163
'hide_filename',
72-
'password',
7364
'one_time_download')) && !is_null($v); // @phpstan-ignore-line
7465
},
7566
ARRAY_FILTER_USE_BOTH
@@ -79,7 +70,7 @@ function ($v, $k) {
7970
* http_build_query will convert them to 1 or 0 integers, which throws an API Exception
8071
*/
8172
$params = http_build_query(array_map(
82-
fn($v)=>is_bool($v) ? ($v ? 'true' : 'false') : $v, // @phpstan-ignore-line
73+
fn($v)=>is_bool($v) ? ($v ? 'true' : 'false') : $v,
8374
$params
8475
));
8576
if ($params !== '') {
@@ -99,13 +90,16 @@ function ($v, $k) {
9990
}
10091
$post_fields['file'] = new CURLStringFile($data, $file_name);
10192
} elseif (isset($args['file_contents'])) {
102-
if (!isset($args['filename']) || $args['filename'] === '') { // @phpstan-ignore-line
93+
if (!isset($args['filename']) || $args['filename'] === '') {
10394
throw new Exception('File name is missing.');
10495
}
10596
$post_fields['file'] = new CURLStringFile($args['file_contents'], $args['filename']);
10697
} else {
10798
throw new Exception('Please provide a url, file or file_contents.');
10899
}
100+
if (isset($args['password']) && $args['password'] !== '') {
101+
$post_fields['password'] = $args['password'];
102+
}
109103
return $this->requestHandler->make(
110104
RequestMethods::PUT,
111105
$url,

tests/WaifuTests/WaifuApiTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PHPUnit\Framework\Attributes\UsesClass;
1515

1616
#[CoversClass(WaifuApi::class)]
17-
#[UsesClass(GlobalMock::class)]
1817
class WaifuApiTest extends TestCase {
1918
private WaifuApi $waifu;
2019
private WaifuResponse $waifuResponse;
@@ -54,7 +53,7 @@ public function testUploadFileExceptions(): void {
5453
foreach ($bad_args as $args) {
5554
try {
5655
// Upload via URL
57-
$this->waifu->uploadFile($args); // @phpstan-ignore-line
56+
$this->waifu->uploadFile($args);
5857
} catch (Exception $e) {
5958
$this->assertSame(Exception::class, get_class($e));
6059
$this->addToAssertionCount(1);

0 commit comments

Comments
 (0)