Skip to content

Commit f3fd42a

Browse files
author
Julien Veyssier
committed
add setting to choose outpud directory
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
1 parent e099fc8 commit f3fd42a

3 files changed

Lines changed: 50 additions & 8 deletions

File tree

lib/Service/DropboxStorageAPIService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public function getStorageSize(string $accessToken, string $refreshToken, string
8383
* @return array
8484
*/
8585
public function startImportDropbox(string $accessToken, string $userId): array {
86-
$targetPath = $this->l10n->t('Dropbox import');
86+
$targetPath = $this->config->getUserValue($userId, Application::APP_ID, 'output_dir', '/Dropbox import');
87+
$targetPath = $targetPath ?: '/Dropbox import';
8788
// create root folder
8889
$userFolder = $this->root->getUserFolder($userId);
8990
if (!$userFolder->nodeExists($targetPath)) {
@@ -122,7 +123,8 @@ public function importDropboxJob(string $userId): void {
122123
$clientSecret = $this->config->getAppValue(Application::APP_ID, 'client_secret', DEFAULT_DROPBOX_CLIENT_SECRET);
123124
$clientSecret = $clientSecret ?: DEFAULT_DROPBOX_CLIENT_SECRET;
124125
// import batch of files
125-
$targetPath = $this->l10n->t('Dropbox import');
126+
$targetPath = $this->config->getUserValue($userId, Application::APP_ID, 'output_dir', '/Dropbox import');
127+
$targetPath = $targetPath ?: '/Dropbox import';
126128
// import by batch of 500 Mo
127129
$alreadyImported = $this->config->getUserValue($userId, Application::APP_ID, 'nb_imported_files', '0');
128130
$alreadyImported = (int) $alreadyImported;

lib/Settings/Personal.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function __construct(string $appName,
4949
*/
5050
public function getForm(): TemplateResponse {
5151
$userName = $this->config->getUserValue($this->userId, Application::APP_ID, 'user_name', '');
52+
$outputDir = $this->config->getUserValue($this->userId, Application::APP_ID, 'output_dir', '/Dropbox import');
5253

5354
// for OAuth
5455
$clientID = $this->config->getAppValue(Application::APP_ID, 'client_id', DEFAULT_DROPBOX_CLIENT_ID);
@@ -64,6 +65,7 @@ public function getForm(): TemplateResponse {
6465
'user_name' => $userName,
6566
'free_space' => $freeSpace,
6667
'user_quota' => $user->getQuota(),
68+
'output_dir' => $outputDir,
6769
];
6870
$this->initialStateService->provideInitialState($this->appName, 'user-config', $userConfig);
6971
$response = new TemplateResponse(Application::APP_ID, 'personalSettings');

src/components/PersonalSettings.vue

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@
5151
<br>
5252
<div v-if="storageSize > 0" id="import-storage">
5353
<h3>{{ t('integration_dropbox', 'Dropbox storage') }}</h3>
54+
<div v-if="!importingDropbox" class="output-selection">
55+
<label for="dropbox-output">
56+
<span class="icon icon-folder" />
57+
{{ t('integration_dropbox', 'Import directory') }}
58+
</label>
59+
<input id="dropbox-output"
60+
:readonly="true"
61+
:value="state.output_dir">
62+
<button
63+
@click="onOutputChange">
64+
<span class="icon-rename" />
65+
</button>
66+
<br><br>
67+
</div>
5468
<label>
5569
<span class="icon icon-folder" />
5670
{{ t('integration_dropbox', 'Dropbox storage size: {formSize}', { formSize: myHumanFileSize(storageSize, true) }) }}
@@ -147,18 +161,16 @@ export default {
147161
methods: {
148162
onLogoutClick() {
149163
this.state.user_name = ''
150-
this.saveOptions()
164+
this.saveOptions({ user_name: this.state.user_name })
151165
},
152166
onAccessCodeInput() {
153167
delay(() => {
154168
this.saveAccessCode()
155169
}, 2000)()
156170
},
157-
saveOptions() {
171+
saveOptions(values) {
158172
const req = {
159-
values: {
160-
user_name: this.state.user_name,
161-
},
173+
values,
162174
}
163175
const url = generateUrl('/apps/integration_dropbox/config')
164176
axios.put(url, req)
@@ -168,7 +180,7 @@ export default {
168180
.catch((error) => {
169181
showError(
170182
t('integration_dropbox', 'Failed to save Dropbox options')
171-
+ ': ' + error.response.request.responseText
183+
+ ': ' + error.response?.request?.responseText
172184
)
173185
})
174186
.then(() => {
@@ -284,6 +296,21 @@ export default {
284296
.then(() => {
285297
})
286298
},
299+
onOutputChange() {
300+
OC.dialogs.filepicker(
301+
t('integration_dropbox', 'Choose where to write imported files'),
302+
(targetPath) => {
303+
if (targetPath === '') {
304+
targetPath = '/'
305+
}
306+
this.state.output_dir = targetPath
307+
this.saveOptions({ output_dir: this.state.output_dir })
308+
},
309+
false,
310+
'httpd/unix-directory',
311+
true
312+
)
313+
},
287314
myHumanFileSize(bytes, approx = false, si = false, dp = 1) {
288315
return humanFileSize(bytes, approx, si, dp)
289316
},
@@ -345,4 +372,15 @@ body.theme--dark .icon-dropbox {
345372
line-height: 38px;
346373
}
347374
375+
.output-selection {
376+
display: flex;
377+
378+
label,
379+
input {
380+
width: 300px;
381+
}
382+
button {
383+
width: 44px !important;
384+
}
385+
}
348386
</style>

0 commit comments

Comments
 (0)