Summary: Navigate through all the conduit pages and address PHP8 incompatibilities. Additionally test out empty form submissions on many of the "create" or "update" APIs and return more contextual errors rather than PHP8 errors. Refs T13588 Test Plan: - Clicked through all the conduit APIs. - Clicked submit on empty forms, or minimally filled-in forms. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley, PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13588 Differential Revision: https://secure.phabricator.com/D21872
59 lines
1.4 KiB
PHP
59 lines
1.4 KiB
PHP
<?php
|
|
|
|
final class FileUploadConduitAPIMethod extends FileConduitAPIMethod {
|
|
|
|
public function getAPIMethodName() {
|
|
return 'file.upload';
|
|
}
|
|
|
|
public function getMethodDescription() {
|
|
return pht('Upload a file to the server.');
|
|
}
|
|
|
|
protected function defineParamTypes() {
|
|
return array(
|
|
'data_base64' => 'required nonempty base64-bytes',
|
|
'name' => 'optional string',
|
|
'viewPolicy' => 'optional valid policy string or <phid>',
|
|
'canCDN' => 'optional bool',
|
|
);
|
|
}
|
|
|
|
protected function defineReturnType() {
|
|
return 'nonempty guid';
|
|
}
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
$viewer = $request->getUser();
|
|
|
|
$name = $request->getValue('name');
|
|
$can_cdn = (bool)$request->getValue('canCDN');
|
|
$view_policy = $request->getValue('viewPolicy');
|
|
|
|
$data = $request->getValue('data_base64');
|
|
if ($data === null) {
|
|
throw new Exception(pht('Field "data_base64" must be non-empty.'));
|
|
}
|
|
$data = $this->decodeBase64($data);
|
|
|
|
$params = array(
|
|
'authorPHID' => $viewer->getPHID(),
|
|
'canCDN' => $can_cdn,
|
|
'isExplicitUpload' => true,
|
|
);
|
|
|
|
if ($name !== null) {
|
|
$params['name'] = $name;
|
|
}
|
|
|
|
if ($view_policy !== null) {
|
|
$params['viewPolicy'] = $view_policy;
|
|
}
|
|
|
|
$file = PhabricatorFile::newFromFileData($data, $params);
|
|
|
|
return $file->getPHID();
|
|
}
|
|
|
|
}
|