@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class FileInfoConduitAPIMethod extends FileConduitAPIMethod {
4
5 public function getAPIMethodName() {
6 return 'file.info';
7 }
8
9 public function getMethodDescription() {
10 return pht('Get information about a file.');
11 }
12
13 public function getMethodStatus() {
14 return self::METHOD_STATUS_DEPRECATED;
15 }
16
17 public function getMethodStatusDescription() {
18 return pht(
19 'This method has been deprecated since %s in favor of %s.',
20 '10/2025',
21 'file.search');
22 }
23
24 protected function defineParamTypes() {
25 return array(
26 'phid' => 'optional phid',
27 'id' => 'optional id',
28 );
29 }
30
31 protected function defineReturnType() {
32 return 'nonempty dict';
33 }
34
35 protected function defineErrorTypes() {
36 return array(
37 'ERR-NOT-FOUND' => pht('No such file exists.'),
38 );
39 }
40
41 protected function execute(ConduitAPIRequest $request) {
42 $phid = $request->getValue('phid');
43 $id = $request->getValue('id');
44
45 $query = id(new PhabricatorFileQuery())
46 ->setViewer($request->getUser());
47 if ($id) {
48 $query->withIDs(array($id));
49 } else {
50 $query->withPHIDs(array($phid));
51 }
52
53 $file = $query->executeOne();
54
55 if (!$file) {
56 throw new ConduitException('ERR-NOT-FOUND');
57 }
58
59 $uri = $file->getInfoURI();
60
61 return array(
62 'id' => $file->getID(),
63 'phid' => $file->getPHID(),
64 'objectName' => 'F'.$file->getID(),
65 'name' => $file->getName(),
66 'mimeType' => $file->getMimeType(),
67 'byteSize' => $file->getByteSize(),
68 'authorPHID' => $file->getAuthorPHID(),
69 'dateCreated' => $file->getDateCreated(),
70 'dateModified' => $file->getDateModified(),
71 'uri' => PhabricatorEnv::getProductionURI($uri),
72 );
73 }
74
75}