@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 FileQueryChunksConduitAPIMethod
4 extends FileConduitAPIMethod {
5
6 public function getAPIMethodName() {
7 return 'file.querychunks';
8 }
9
10 public function getMethodDescription() {
11 return pht('Get information about file chunks.');
12 }
13
14 protected function defineParamTypes() {
15 return array(
16 'filePHID' => 'phid',
17 );
18 }
19
20 protected function defineReturnType() {
21 return 'list<wild>';
22 }
23
24 protected function defineErrorTypes() {
25 return array(
26 'ERR-BAD-PHID' => pht('Must pass a PHID.'),
27 );
28 }
29
30 protected function execute(ConduitAPIRequest $request) {
31 $viewer = $request->getUser();
32
33 $file_phid = $request->getValue('filePHID');
34 if (!$file_phid) {
35 throw new ConduitException('ERR-BAD-PHID');
36 }
37 $file = $this->loadFileByPHID($viewer, $file_phid);
38 $chunks = $this->loadFileChunks($viewer, $file);
39
40 $results = array();
41 foreach ($chunks as $chunk) {
42 $results[] = array(
43 'byteStart' => $chunk->getByteStart(),
44 'byteEnd' => $chunk->getByteEnd(),
45 'complete' => (bool)$chunk->getDataFilePHID(),
46 );
47 }
48
49 return $results;
50 }
51
52}