MCPcopy Index your code
hub / github.com/vastsa/FileCodeBox / update_file_metadata

Method update_file_metadata

apps/admin/services.py:234–273  ·  view source on GitHub ↗
(
        self,
        file_id: int,
        note: Optional[str],
        tags: Optional[list[str]],
        update_note: bool,
        update_tags: bool,
    )

Source from the content-addressed store, hash-verified

232 return self._normalize_file_metadata(record.value if record else None)
233
234 async def update_file_metadata(
235 self,
236 file_id: int,
237 note: Optional[str],
238 tags: Optional[list[str]],
239 update_note: bool,
240 update_tags: bool,
241 ) -> dict[str, Any]:
242 file_code = await FileCodes.filter(id=file_id).first()
243 if not file_code:
244 raise HTTPException(status_code=404, detail="文件不存在")
245
246 current_metadata = await self.get_file_metadata(file_id)
247 next_metadata = dict(current_metadata)
248 if update_note:
249 next_metadata["note"] = self._normalize_metadata_note(note)
250 if update_tags:
251 next_metadata["tags"] = self._normalize_metadata_tags(tags)
252
253 now = await get_now()
254 updated_at = now.isoformat()
255 next_metadata["updatedAt"] = updated_at
256 next_metadata["updated_at"] = updated_at
257 await KeyValue.update_or_create(
258 key=self._file_metadata_key(file_id),
259 defaults={"value": next_metadata},
260 )
261 await self.record_admin_activity(
262 action="file.metadata_update",
263 target_type="file",
264 target_id=file_id,
265 target_name=self._build_file_activity_name(file_code),
266 count=1,
267 meta={
268 "updateNote": update_note,
269 "updateTags": update_tags,
270 "tagCount": len(next_metadata["tags"]),
271 },
272 )
273 return await self.get_file_detail(file_id)
274
275 async def list_file_view_presets(self) -> dict[str, Any]:
276 presets = await self._get_file_view_presets()

Callers 1

update_file_metadataFunction · 0.80

Calls 11

get_file_metadataMethod · 0.95
_file_metadata_keyMethod · 0.95
record_admin_activityMethod · 0.95
get_file_detailMethod · 0.95
get_nowFunction · 0.90
firstMethod · 0.45
filterMethod · 0.45
update_or_createMethod · 0.45

Tested by

no test coverage detected