-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathWorkspaceService.php
More file actions
65 lines (54 loc) 路 1.41 KB
/
Copy pathWorkspaceService.php
File metadata and controls
65 lines (54 loc) 路 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Text\Service;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\NotFoundException;
use OCP\Files\StorageInvalidException;
use OCP\IL10N;
class WorkspaceService {
private IL10N $l10n;
public const DEFAULT_FILENAME = 'Readme.md';
private const SUPPORTED_STATIC_FILENAMES = [
self::DEFAULT_FILENAME,
'README.md',
'readme.md',
'.Readme.md',
];
public function __construct(IL10N $l10n) {
$this->l10n = $l10n;
}
public function getFile(Folder $folder): ?File {
try {
$cache = $folder->getStorage()->getCache();
$internalPath = $folder->getInternalPath();
} catch (StorageInvalidException) {
return null;
}
foreach ($this->getSupportedFilenames() as $filename) {
try {
$cacheEntry = $cache->get($internalPath . '/' . $filename);
if ($cacheEntry !== false && $cacheEntry->getMimeType() !== ICacheEntry::DIRECTORY_MIMETYPE) {
$file = $folder->get($filename);
if ($file instanceof File) {
return $file;
}
}
} catch (NotFoundException) {
continue;
}
}
return null;
}
/** @return string[] */
public function getSupportedFilenames(): array {
return array_merge([
$this->l10n->t('Readme') . '.md'
], self::SUPPORTED_STATIC_FILENAMES);
}
}