mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 13:00:56 +01:00
Add a 'file.info' Conduit method
Summary: Need this for 'arc upload' and 'arc download'. Given a file PHID or ID, provides information about it. Test Plan: - Implemented 'arc upload' and 'arc download' based on 'file.info'. - Used Conduit API console to test method. Reviewed By: codeblock Reviewers: codeblock, jungejason, tuomaspelkonen, aran CC: aran, codeblock, epriestley Differential Revision: 741
This commit is contained in:
parent
ab0f09d115
commit
eb23539141
4 changed files with 108 additions and 0 deletions
|
@ -106,6 +106,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'applications/conduit/method/diffusion/getrecentcommitsbypath',
|
||||
'ConduitAPI_feed_publish_Method' => 'applications/conduit/method/feed/publish',
|
||||
'ConduitAPI_file_download_Method' => 'applications/conduit/method/file/download',
|
||||
'ConduitAPI_file_info_Method' => 'applications/conduit/method/file/info',
|
||||
'ConduitAPI_file_upload_Method' => 'applications/conduit/method/file/upload',
|
||||
'ConduitAPI_maniphest_info_Method' => 'applications/conduit/method/maniphest/info',
|
||||
'ConduitAPI_paste_info_Method' => 'applications/conduit/method/paste/info',
|
||||
|
@ -724,6 +725,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_feed_publish_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_file_download_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_file_info_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_maniphest_info_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_paste_info_Method' => 'ConduitAPIMethod',
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group conduit
|
||||
*/
|
||||
class ConduitAPI_file_info_Method extends ConduitAPIMethod {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return "Get information about a file.";
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'phid' => 'optional phid',
|
||||
'id' => 'optional id',
|
||||
);
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'nonempty dict';
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
return array(
|
||||
'ERR-NOT-FOUND' => 'No such file exists.',
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
$phid = $request->getValue('phid');
|
||||
$id = $request->getValue('id');
|
||||
|
||||
if ($id) {
|
||||
$file = id(new PhabricatorFile())->load($id);
|
||||
} else {
|
||||
$file = id(new PhabricatorFile())->loadOneWhere(
|
||||
'phid = %s',
|
||||
$phid);
|
||||
}
|
||||
|
||||
if (!$file) {
|
||||
throw new ConduitException('ERR-NOT-FOUND');
|
||||
}
|
||||
|
||||
$uri = $file->getBestURI();
|
||||
|
||||
return array(
|
||||
'id' => $file->getID(),
|
||||
'phid' => $file->getPHID(),
|
||||
'objectName' => 'F'.$file->getID(),
|
||||
'name' => $file->getName(),
|
||||
'mimeType' => $file->getMimeType(),
|
||||
'byteSize' => $file->getByteSize(),
|
||||
'authorPHID' => $file->getAuthorPHID(),
|
||||
'dateCreated' => $file->getDateCreated(),
|
||||
'dateModified' => $file->getDateModified(),
|
||||
'uri' => PhabricatorEnv::getProductionURI($uri),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
17
src/applications/conduit/method/file/info/__init__.php
Normal file
17
src/applications/conduit/method/file/info/__init__.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/conduit/method/base');
|
||||
phutil_require_module('phabricator', 'applications/conduit/protocol/exception');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/file');
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('ConduitAPI_file_info_Method.php');
|
|
@ -219,6 +219,18 @@ class PhabricatorFile extends PhabricatorFileDAO {
|
|||
return PhabricatorFileURI::getViewURIForPHID($this->getPHID());
|
||||
}
|
||||
|
||||
public function getInfoURI() {
|
||||
return '/file/info/'.$this->getPHID().'/';
|
||||
}
|
||||
|
||||
public function getBestURI() {
|
||||
if ($this->isViewableInBrowser()) {
|
||||
return $this->getViewURI();
|
||||
} else {
|
||||
return $this->getInfoURI();
|
||||
}
|
||||
}
|
||||
|
||||
public function getThumb60x45URI() {
|
||||
return '/file/xform/thumb-60x45/'.$this->getPHID().'/';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue