use correct convex function and change how the edit html gets the file id

This commit is contained in:
2026-04-01 21:05:07 +02:00
parent 5bbc100d83
commit 65951a23ce
3 changed files with 17 additions and 14 deletions
+6 -2
View File
@@ -72,8 +72,12 @@ class ConvexDB(ConvexDbBase):
args={ 'file_id': file_id, 'user_id': user_id }
)
async def get_file_informations(self, file_id:str):
pass
async def get_file_informations(self, file_id:str, user_id:str):
data = await self.run_query(
name='files:getFileByIdAndUser',
args={ 'file_id': file_id, 'user_id': user_id }
)
return data
# File Access Quary Functions
async def add_file_access(self, file_id: str, ip_address:str, status:str, user_agent:str):
+4 -5
View File
@@ -71,17 +71,16 @@ async def file_info(file_id, user):
@login_required
@feature_flag_required("nanoshare_files-edit", fallback=False, status_code=404)
async def file_edit(file_id, user):
files_data = await current_app.convex.get_files(user_id=user["sub"])
file_data = find_file(files_data, file_id)
file_data = await current_app.convex.get_file_informations(file_id=file_id, user_id=user["sub"])
if not file_data:
abort(404)
share_url = request.url_root.rstrip("/") + f"/-{file_id}"
return await render_template(
"views/webpage/files/edit.htm", file=file_data, share_url=share_url
"views/webpage/files/edit.htm", file=file_data, share_url=share_url, file_id=file_id
)
@side_main_bp.post("/api/files/<path:file_id>/edit")
@side_main_bp.put("/api/file/<path:file_id>")
@login_required
@feature_flag_required("nanoshare_files-edit", fallback=False, status_code=404)
async def file_edit_api(file_id, user):
@@ -114,7 +113,7 @@ async def file_edit_api(file_id, user):
return jsonify({"ok": True})
@side_main_bp.post("/api/files/<path:file_id>/delete")
@side_main_bp.delete("/api/file/<path:file_id>")
@login_required
@feature_flag_required("nanoshare_files-edit", fallback=False, status_code=404)
async def file_delete_api(file_id, user):
+7 -7
View File
@@ -44,7 +44,7 @@
</tr>
<tr>
<th scope="row">File ID</th>
<td><code>{{ file.file_id }}</code></td>
<td><code>{{ file_id }}</code></td>
</tr>
<tr>
<th scope="row">Uploaded at</th>
@@ -88,7 +88,7 @@
<div class="save-row">
<button id="saveBtn" class="btn" type="button">Save changes</button>
<a class="btn btn-ghost" href="{{ url_for('side_main.file_info', file_id=file.file_id) }}">View info</a>
<a class="btn btn-ghost" href="{{ url_for('side_main.file_info', file_id=file_id) }}">View info</a>
<a class="btn btn-ghost" href="{{ url_for('side_main.files_list') }}">Back to files</a>
</div>
<div class="status-row"><span id="status" class="status"></span></div>
@@ -102,7 +102,7 @@
</main>
<script>
const fileId = '{{ file.file_id }}';
const fileId = '{{ file_id }}';
const initialExpires = '{{ file.expires_at }}';
const expiresMode = document.getElementById('expiresMode');
const customWrap = document.getElementById('customWrap');
@@ -173,8 +173,8 @@
setStatus('Saving...');
try {
const response = await fetch(`/api/files/${encodeURIComponent(fileId)}/edit`, {
method: 'POST',
const response = await fetch(`/api/file/${encodeURIComponent(fileId)}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ file_name: fileName, note, expires }),
});
@@ -194,8 +194,8 @@
setStatus('Deleting...');
try {
const response = await fetch(`/api/files/${encodeURIComponent(fileId)}/delete`, {
method: 'POST',
const response = await fetch(`/api/file/${encodeURIComponent(fileId)}`, {
method: 'DELETE',
});
const data = await response.json();
if (!response.ok || !data.ok) {