-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathExternalShare.php
More file actions
146 lines (134 loc) · 4.68 KB
/
Copy pathExternalShare.php
File metadata and controls
146 lines (134 loc) · 4.68 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Sharing\External;
use OC\Files\Filesystem;
use OCA\Files_Sharing\ResponseDefinitions;
use OCP\AppFramework\Db\SnowflakeAwareEntity;
use OCP\DB\Types;
use OCP\IGroup;
use OCP\IUser;
use OCP\Share\IShare;
/**
* @method string getParent()
* @method void setParent(string $parent)
* @method int|null getShareType()
* @method void setShareType(int $shareType)
* @method string getRemote()
* @method void setRemote(string $remote)
* @method string getRemoteId()
* @method void setRemoteId(string $remoteId)
* @method string getRefreshToken()
* @method void setRefreshToken(string $refreshToken)
* @method string|null getPassword()
* @method void setPassword(?string $password)
* @method string|null getAccessToken()
* @method void setAccessToken(?string $accessToken)
* @method int|null getAccessTokenExpires()
* @method void setAccessTokenExpires(?int $accessTokenExpires)
* @method string getName()
* @method string getOwner()
* @method void setOwner(string $owner)
* @method string getUser()
* @method void setUser(string $user)
* @method string getMountpoint()
* @method string getMountpointHash()
* @method void setMountpointHash(string $mountPointHash)
* @method int getAccepted()
* @method void setAccepted(int $accepted)
*
* @psalm-import-type Files_SharingRemoteShare from ResponseDefinitions
*/
class ExternalShare extends SnowflakeAwareEntity implements \JsonSerializable {
protected string $parent = '-1';
protected ?int $shareType = null;
protected ?string $remote = null;
protected ?string $remoteId = null;
protected ?string $refreshToken = null;
protected ?string $password = null;
protected ?string $accessToken = null;
protected ?int $accessTokenExpires = null;
protected ?string $name = null;
protected ?string $owner = null;
protected ?string $user = null;
protected ?string $mountpoint = null;
protected ?string $mountpointHash = null;
protected ?int $accepted = null;
public function __construct() {
$this->addType('id', Types::STRING); // Stored as a bigint
$this->addType('parent', Types::STRING); // Stored as a bigint
$this->addType('shareType', Types::INTEGER);
$this->addType('remote', Types::STRING);
$this->addType('remoteId', Types::STRING);
$this->addType('refreshToken', Types::STRING);
$this->addType('password', Types::STRING);
$this->addType('accessToken', Types::STRING);
$this->addType('accessTokenExpires', Types::INTEGER);
$this->addType('name', Types::STRING);
$this->addType('owner', Types::STRING);
$this->addType('user', Types::STRING);
$this->addType('mountpoint', Types::STRING);
$this->addType('mountpointHash', Types::STRING);
$this->addType('accepted', Types::INTEGER);
}
public function setMountpoint(string $mountPoint): void {
$this->setter('mountpoint', [$mountPoint]);
$this->setMountpointHash(md5($mountPoint));
}
public function setName(string $name): void {
$name = Filesystem::normalizePath('/' . $name);
$this->setter('name', [$name]);
}
public function setShareWith(IUser|IGroup $shareWith): void {
$this->setUser($shareWith instanceof IGroup ? $shareWith->getGID() : $shareWith->getUID());
}
/**
* @return Files_SharingRemoteShare
*/
#[\Override]
public function jsonSerialize(): array {
$parent = $this->getParent();
return [
'id' => (string)$this->getId(),
'parent' => $parent,
'share_type' => $this->getShareType() ?? IShare::TYPE_USER, // unfortunately nullable on the DB level, but never null.
'remote' => $this->getRemote(),
'remote_id' => $this->getRemoteId(),
'refresh_token' => $this->getRefreshToken(),
'name' => $this->getName(),
'owner' => $this->getOwner(),
'user' => $this->getUser(),
'mountpoint' => $this->getMountpoint(),
'accepted' => $this->getAccepted(),
// Added later on
'file_id' => null,
'mimetype' => null,
'permissions' => null,
'mtime' => null,
'type' => null,
'item_size' => null,
];
}
/**
* @internal For unit tests
* @return ExternalShare
*/
public function clone(): self {
$newShare = new ExternalShare();
$newShare->setParent($this->getParent());
$newShare->setShareType($this->getShareType());
$newShare->setRemote($this->getRemote());
$newShare->setRemoteId($this->getRemoteId());
$newShare->setRefreshToken($this->getRefreshToken());
$newShare->setPassword($this->getPassword());
$newShare->setName($this->getName());
$newShare->setOwner($this->getOwner());
$newShare->setMountpoint($this->getMountpoint());
$newShare->setAccepted($this->getAccepted());
$newShare->setPassword($this->getPassword());
return $newShare;
}
}