Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: moved the password field from URI param to body param #9

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions src/WaifuApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,16 @@
*
* @link https://waifuvault.moe/
*
* @phpstan-type FileUpload array{
* file: string,
* filename?: string
* }
* @phpstan-type FileContentUpload array{
* file_contents: string,
* filename: string
* }
* @phpstan-type UrlUpload array{
* url: string
* }
*
* @phpstan-type uploadFileArg array{
* file?: string,
* url?: string,
* filename?: string,
* file_contents?: string,
* expires?:string,
* hide_filename?:bool,
* password?:string,
* one_time_download?:bool
* }&(FileUpload|FileContentUpload|UrlUpload)
* }
*
* @phpstan-type modifyFileArg array{
* token: string,
Expand Down Expand Up @@ -69,7 +61,6 @@ function ($v, $k) {
return in_array($k, array(
'expires',
'hide_filename',
'password',
'one_time_download')) && !is_null($v); // @phpstan-ignore-line
},
ARRAY_FILTER_USE_BOTH
Expand All @@ -79,7 +70,7 @@ function ($v, $k) {
* http_build_query will convert them to 1 or 0 integers, which throws an API Exception
*/
$params = http_build_query(array_map(
fn($v)=>is_bool($v) ? ($v ? 'true' : 'false') : $v, // @phpstan-ignore-line
fn($v)=>is_bool($v) ? ($v ? 'true' : 'false') : $v,
$params
));
if ($params !== '') {
Expand All @@ -99,13 +90,16 @@ function ($v, $k) {
}
$post_fields['file'] = new CURLStringFile($data, $file_name);
} elseif (isset($args['file_contents'])) {
if (!isset($args['filename']) || $args['filename'] === '') { // @phpstan-ignore-line
if (!isset($args['filename']) || $args['filename'] === '') {
throw new Exception('File name is missing.');
}
$post_fields['file'] = new CURLStringFile($args['file_contents'], $args['filename']);
} else {
throw new Exception('Please provide a url, file or file_contents.');
}
if (isset($args['password']) && $args['password'] !== '') {
$post_fields['password'] = $args['password'];
}
return $this->requestHandler->make(
RequestMethods::PUT,
$url,
Expand Down
3 changes: 1 addition & 2 deletions tests/WaifuTests/WaifuApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPUnit\Framework\Attributes\UsesClass;

#[CoversClass(WaifuApi::class)]
#[UsesClass(GlobalMock::class)]
class WaifuApiTest extends TestCase {
private WaifuApi $waifu;
private WaifuResponse $waifuResponse;
Expand Down Expand Up @@ -54,7 +53,7 @@ public function testUploadFileExceptions(): void {
foreach ($bad_args as $args) {
try {
// Upload via URL
$this->waifu->uploadFile($args); // @phpstan-ignore-line
$this->waifu->uploadFile($args);
} catch (Exception $e) {
$this->assertSame(Exception::class, get_class($e));
$this->addToAssertionCount(1);
Expand Down