mirror of
https://github.com/filegator/filegator.git
synced 2025-08-06 13:17:03 +02:00
File edit
This commit is contained in:
@@ -170,4 +170,25 @@ class FileController
|
|||||||
|
|
||||||
return $response->json('Done');
|
return $response->json('Done');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function saveContent(Request $request, Response $response)
|
||||||
|
{
|
||||||
|
$path = $request->input('dir', $this->session->get(self::SESSION_CWD, $this->separator));
|
||||||
|
|
||||||
|
$name = $request->input('name');
|
||||||
|
$content = $request->input('content');
|
||||||
|
|
||||||
|
$stream = tmpfile();
|
||||||
|
fwrite($stream, $content);
|
||||||
|
rewind($stream);
|
||||||
|
|
||||||
|
$res = $this->storage->deleteFile($path.$this->separator.$name);
|
||||||
|
$res = $this->storage->store($path, $name, $stream);
|
||||||
|
|
||||||
|
if (is_resource($stream)) {
|
||||||
|
fclose($stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response->json('Done');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -256,4 +256,15 @@ return [
|
|||||||
'permissions' => [
|
'permissions' => [
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'route' => [
|
||||||
|
'POST', '/savecontent', '\Filegator\Controllers\FileController@saveContent',
|
||||||
|
],
|
||||||
|
'roles' => [
|
||||||
|
'guest', 'user', 'admin',
|
||||||
|
],
|
||||||
|
'permissions' => [
|
||||||
|
'read', 'write',
|
||||||
|
],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
@@ -198,6 +198,16 @@ const api = {
|
|||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
saveContent (params) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
axios.post('savecontent', {
|
||||||
|
name: params.name,
|
||||||
|
content: params.content,
|
||||||
|
})
|
||||||
|
.then(res => resolve(res.data))
|
||||||
|
.catch(error => reject(error))
|
||||||
|
})
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default api
|
export default api
|
||||||
|
@@ -70,6 +70,7 @@ const data = {
|
|||||||
'Updated': 'Обновено',
|
'Updated': 'Обновено',
|
||||||
'Deleted': 'изтрити',
|
'Deleted': 'изтрити',
|
||||||
'Your file is ready': 'Вашия файл е готов',
|
'Your file is ready': 'Вашия файл е готов',
|
||||||
|
'View': 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default data
|
export default data
|
||||||
|
@@ -70,6 +70,7 @@ const data = {
|
|||||||
'Updated': '已上传',
|
'Updated': '已上传',
|
||||||
'Deleted': '已删除',
|
'Deleted': '已删除',
|
||||||
'Your file is ready': '您的文件已备妥',
|
'Your file is ready': '您的文件已备妥',
|
||||||
|
'View': 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default data
|
export default data
|
||||||
|
@@ -70,6 +70,7 @@ const data = {
|
|||||||
'Updated': 'Aangepast',
|
'Updated': 'Aangepast',
|
||||||
'Deleted': 'Verwijderd',
|
'Deleted': 'Verwijderd',
|
||||||
'Your file is ready': 'Uw bestand is verwerkt',
|
'Your file is ready': 'Uw bestand is verwerkt',
|
||||||
|
'View': 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default data
|
export default data
|
||||||
|
@@ -70,6 +70,7 @@ const data = {
|
|||||||
'Updated': 'Mis à jour',
|
'Updated': 'Mis à jour',
|
||||||
'Deleted': 'Supprimé',
|
'Deleted': 'Supprimé',
|
||||||
'Your file is ready': 'Votre fichier est prêt',
|
'Your file is ready': 'Votre fichier est prêt',
|
||||||
|
'View': 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default data
|
export default data
|
||||||
|
@@ -70,6 +70,7 @@ const data = {
|
|||||||
'Updated': 'Aktualisiert',
|
'Updated': 'Aktualisiert',
|
||||||
'Deleted': 'Gelöscht',
|
'Deleted': 'Gelöscht',
|
||||||
'Your file is ready': 'Deine Datei ist fertig',
|
'Your file is ready': 'Deine Datei ist fertig',
|
||||||
|
'View': 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default data
|
export default data
|
||||||
|
@@ -70,6 +70,7 @@ const data = {
|
|||||||
'Updated': 'Diperbarui',
|
'Updated': 'Diperbarui',
|
||||||
'Deleted': 'Dihapus',
|
'Deleted': 'Dihapus',
|
||||||
'Your file is ready': 'File Anda sudah siap',
|
'Your file is ready': 'File Anda sudah siap',
|
||||||
|
'View': 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default data
|
export default data
|
||||||
|
@@ -70,6 +70,7 @@ const data = {
|
|||||||
'Updated': 'Atnaujintas',
|
'Updated': 'Atnaujintas',
|
||||||
'Deleted': 'Ištrintas',
|
'Deleted': 'Ištrintas',
|
||||||
'Your file is ready': 'Jūsų failas paruoštas',
|
'Your file is ready': 'Jūsų failas paruoštas',
|
||||||
|
'View': 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default data
|
export default data
|
||||||
|
@@ -70,6 +70,7 @@ const data = {
|
|||||||
'Updated': 'Atualizado',
|
'Updated': 'Atualizado',
|
||||||
'Deleted': 'Excluido',
|
'Deleted': 'Excluido',
|
||||||
'Your file is ready': 'Seu arquivo está pronto',
|
'Your file is ready': 'Seu arquivo está pronto',
|
||||||
|
'View': 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default data
|
export default data
|
||||||
|
@@ -70,6 +70,7 @@ const data = {
|
|||||||
'Updated': 'Izmenjeno',
|
'Updated': 'Izmenjeno',
|
||||||
'Deleted': 'Obrisano',
|
'Deleted': 'Obrisano',
|
||||||
'Your file is ready': 'Vaš fajl je spreman',
|
'Your file is ready': 'Vaš fajl je spreman',
|
||||||
|
'View': 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default data
|
export default data
|
||||||
|
@@ -70,6 +70,7 @@ const data = {
|
|||||||
'Updated': 'Actualizado',
|
'Updated': 'Actualizado',
|
||||||
'Deleted': 'Eliminado',
|
'Deleted': 'Eliminado',
|
||||||
'Your file is ready': 'Su fichero está listo',
|
'Your file is ready': 'Su fichero está listo',
|
||||||
|
'View': 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default data
|
export default data
|
||||||
|
@@ -70,6 +70,7 @@ const data = {
|
|||||||
'Updated': 'Güncellendi',
|
'Updated': 'Güncellendi',
|
||||||
'Deleted': 'Silindi',
|
'Deleted': 'Silindi',
|
||||||
'Your file is ready': 'Dosyanız Hazır',
|
'Your file is ready': 'Dosyanız Hazır',
|
||||||
|
'View': 'View',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default data
|
export default data
|
||||||
|
@@ -113,7 +113,7 @@
|
|||||||
<b-dropdown-item v-if="props.row.type == 'file' && can('download')" aria-role="listitem" @click="download(props.row)">
|
<b-dropdown-item v-if="props.row.type == 'file' && can('download')" aria-role="listitem" @click="download(props.row)">
|
||||||
<b-icon icon="download" size="is-small" /> {{ lang('Download') }}
|
<b-icon icon="download" size="is-small" /> {{ lang('Download') }}
|
||||||
</b-dropdown-item>
|
</b-dropdown-item>
|
||||||
<b-dropdown-item v-if="props.row.type == 'file' && can('read')" aria-role="listitem" @click="preview(props.row)">
|
<b-dropdown-item v-if="props.row.type == 'file' && can(['read', 'download'])" aria-role="listitem" @click="preview(props.row)">
|
||||||
<b-icon icon="file-alt" size="is-small" /> {{ lang('View') }}
|
<b-icon icon="file-alt" size="is-small" /> {{ lang('View') }}
|
||||||
</b-dropdown-item>
|
</b-dropdown-item>
|
||||||
<b-dropdown-item v-if="can('write')" aria-role="listitem" @click="copy($event, props.row)">
|
<b-dropdown-item v-if="can('write')" aria-role="listitem" @click="copy($event, props.row)">
|
||||||
@@ -252,7 +252,7 @@ export default {
|
|||||||
itemClick(item) {
|
itemClick(item) {
|
||||||
if (item.type == 'dir' || item.type == 'back') {
|
if (item.type == 'dir' || item.type == 'back') {
|
||||||
this.goTo(item.path)
|
this.goTo(item.path)
|
||||||
} else {
|
} else if (this.can(['read', 'download'])) {
|
||||||
this.preview(item)
|
this.preview(item)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@@ -13,6 +13,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<footer class="modal-card-foot">
|
<footer class="modal-card-foot">
|
||||||
|
<button v-if="isText() && can(['write'])" class="button" type="button" @click="saveFile()">
|
||||||
|
{{ lang('Save') }}
|
||||||
|
</button>
|
||||||
<button class="button" type="button" @click="$parent.close()">
|
<button class="button" type="button" @click="$parent.close()">
|
||||||
{{ lang('Close') }}
|
{{ lang('Close') }}
|
||||||
</button>
|
</button>
|
||||||
@@ -54,6 +57,20 @@ export default {
|
|||||||
hasExtension(exts) {
|
hasExtension(exts) {
|
||||||
return (new RegExp('(' + exts.join('|').replace(/\./g, '\\.') + ')$', 'i')).test(this.item.path)
|
return (new RegExp('(' + exts.join('|').replace(/\./g, '\\.') + ')$', 'i')).test(this.item.path)
|
||||||
},
|
},
|
||||||
|
saveFile() {
|
||||||
|
api.saveContent({
|
||||||
|
name: this.item.name,
|
||||||
|
content: this.content,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
this.$toast.open({
|
||||||
|
message: this.lang('Updated'),
|
||||||
|
type: 'is-success',
|
||||||
|
})
|
||||||
|
this.$parent.close()
|
||||||
|
})
|
||||||
|
.catch(error => this.handleError(error))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@@ -586,4 +586,49 @@ class FilesTest extends TestCase
|
|||||||
|
|
||||||
$this->assertOk();
|
$this->assertOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUpdateFileContent()
|
||||||
|
{
|
||||||
|
$username = 'john@example.com';
|
||||||
|
$this->signIn($username, 'john123');
|
||||||
|
|
||||||
|
mkdir(TEST_REPOSITORY.'/john');
|
||||||
|
file_put_contents(TEST_REPOSITORY.'/john/john.txt', 'lorem ipsum');
|
||||||
|
|
||||||
|
$this->sendRequest('POST', '/savecontent', [
|
||||||
|
'name' => 'john.txt',
|
||||||
|
'content' => 'lorem ipsum new'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertOk();
|
||||||
|
|
||||||
|
$updated = file_get_contents(TEST_REPOSITORY.'/john/john.txt');
|
||||||
|
|
||||||
|
$this->assertEquals($updated, 'lorem ipsum new');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateFileContentInSubDir()
|
||||||
|
{
|
||||||
|
$username = 'john@example.com';
|
||||||
|
$this->signIn($username, 'john123');
|
||||||
|
|
||||||
|
mkdir(TEST_REPOSITORY.'/john');
|
||||||
|
mkdir(TEST_REPOSITORY.'/john/sub');
|
||||||
|
file_put_contents(TEST_REPOSITORY.'/john/sub/john.txt', 'lorem ipsum');
|
||||||
|
|
||||||
|
$this->sendRequest('POST', '/changedir', [
|
||||||
|
'to' => '/sub/',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->sendRequest('POST', '/savecontent', [
|
||||||
|
'name' => 'john.txt',
|
||||||
|
'content' => 'lorem ipsum new'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertOk();
|
||||||
|
|
||||||
|
$updated = file_get_contents(TEST_REPOSITORY.'/john/sub/john.txt');
|
||||||
|
|
||||||
|
$this->assertEquals($updated, 'lorem ipsum new');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user