Skip to content

Commit

Permalink
add fake form to download tables export
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <salimbelakkaf@outlook.de>
  • Loading branch information
grnd-alt committed Jul 22, 2024
1 parent b31c9f7 commit 082c986
Show file tree
Hide file tree
Showing 5 changed files with 4,167 additions and 5,072 deletions.
31 changes: 26 additions & 5 deletions lib/Controller/Api1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,35 @@ public function createTable(string $title, ?string $emoji, string $template = 'c

/**
* returns table scheme
* @param int $tableId
* @return \OCP\AppFramework\Http\DataResponse
*
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* @param int $tableId Table ID
* @return DataResponse<Http::STATUS_OK, TablesTable, array{'Content-Disposition'?:string,'Content-Type'?:string}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
*
* 200: Table returned
* 403: No permissions
* 404: Not found
*/
public function showScheme(int $tableId): DataResponse {
return $this->handleError(function () use ($tableId) {
try {
$scheme = $this->tableService->getScheme($tableId);
return new DataResponse($scheme->jsonSerialize(), http::STATUS_OK, ["Content-Disposition" => "attachment", "filename" => $scheme->getTitle() . ".json", "Content-Type" => "application/octet-stream"]);
});
return new DataResponse($scheme->jsonSerialize(), http::STATUS_OK, ['Content-Disposition' => 'attachment; filename="'.$scheme->getTitle() . '.json"', 'Content-Type' => 'application/octet-stream']);
} catch (PermissionError $e) {
$this->logger->warning('A permission error occurred: ' . $e->getMessage());
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_FORBIDDEN);
} catch (NotFoundError $e) {
$this->logger->warning('A not found error occurred: ' . $e->getMessage());
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_NOT_FOUND);
} catch (InternalError|Exception $e) {
$this->logger->warning('An internal error or exception occurred: '.$e->getMessage());
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_INTERNAL_SERVER_ERROR);
}
}

/**
Expand Down
2 changes: 0 additions & 2 deletions lib/Controller/ApiTablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace OCA\Tables\Controller;

use Exception;
use OCA\Tables\Db\Column;
use OCA\Tables\Db\View;
use OCA\Tables\Errors\InternalError;
use OCA\Tables\Errors\NotFoundError;
use OCA\Tables\Errors\PermissionError;
Expand Down
99 changes: 99 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,105 @@
}
}
},
"/index.php/apps/tables/api/1/tables/{tableId}/scheme": {
"get": {
"operationId": "api1-show-scheme",
"summary": "returns table scheme",
"tags": [
"api1"
],
"security": [
{
"basic_auth": []
}
],
"parameters": [
{
"name": "tableId",
"in": "path",
"description": "Table ID",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
}
],
"responses": {
"200": {
"description": "Table returned",
"headers": {
"Content-Disposition": {
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Table"
}
}
}
},
"403": {
"description": "No permissions",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string"
}
}
}
}
}
},
"500": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string"
}
}
}
}
}
},
"404": {
"description": "Not found",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string"
}
}
}
}
}
}
}
}
},
"/index.php/apps/tables/api/1/tables/{tableId}/views": {
"get": {
"operationId": "api1-index-views",
Expand Down
26 changes: 15 additions & 11 deletions src/modules/navigation/partials/NavigationTableItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,13 @@ import StarOutline from 'vue-material-design-icons/StarOutline.vue'
import ArchiveArrowDown from 'vue-material-design-icons/ArchiveArrowDown.vue'
import ArchiveArrowUpOutline from 'vue-material-design-icons/ArchiveArrowUpOutline.vue'
import permissionsMixin from '../../../shared/components/ncTable/mixins/permissionsMixin.js'
import { getCurrentUser } from '@nextcloud/auth'
import { getCurrentUser, getRequestToken } from '@nextcloud/auth'
import Connection from 'vue-material-design-icons/Connection.vue'
import Import from 'vue-material-design-icons/Import.vue'
import NavigationViewItem from './NavigationViewItem.vue'
import PlaylistPlus from 'vue-material-design-icons/PlaylistPlus.vue'
import IconRename from 'vue-material-design-icons/Rename.vue'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { generateUrl } from '@nextcloud/router'
export default {
Expand Down Expand Up @@ -246,14 +245,19 @@ export default {
},
exportFile() {
axios.get(generateOcsUrl(`/apps/tables/api/2/tables/scheme/${this.table.id}`)).then(res => {
const blob = new Blob([JSON.stringify(res.data.ocs.data)], { type: 'application/json' })
const link = document.createElement('a')
link.href = URL.createObjectURL(blob)
link.download = this.table.title
link.click()
URL.revokeObjectURL(link.href)
})
const form = document.createElement('form')
form.method = 'GET'
form.action = generateUrl(`/apps/tables/api/1/tables/${this.table.id}/scheme`)
const token = document.createElement('input')
token.type = 'hidden'
token.name = 'requesttoken'
token.value = getRequestToken()
form.appendChild(token)
document.body.appendChild(form)
form.submit()
},
async actionShowShare() {
Expand Down
Loading

0 comments on commit 082c986

Please sign in to comment.