mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-06 11:58:30 +01:00
440ef5b7a7
Summary: Ref T12464. We currently use SHA1 to detect when two files have the same content so we don't have to store two copies of the data. Now that a SHA1 collision is known, this is theoretically dangerous. T12464 describes the shape of a possible attack. Before replacing this with something more robust, shore things up so things work correctly if we don't hash at all. This mechanism is entirely optional; it only helps us store less data if some files are duplicates. (This mechanism is also less important now than it once was, before we added temporary files.) Test Plan: Uploaded multiple identical files, saw the uploads work and the files store separate copies of the same data. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12464 Differential Revision: https://secure.phabricator.com/D17619
55 lines
1.3 KiB
PHP
55 lines
1.3 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');
|
|
$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();
|
|
}
|
|
|
|
}
|