MCPcopy
hub / github.com/1Panel-dev/MaxKB / edit

Method edit

apps/tools/serializers/tool.py:1161–1187  ·  view source on GitHub ↗
(self, with_valid=True)

Source from the content-addressed store, hash-verified

1159 raise AppApiException(500, _("Tool id does not exist"))
1160
1161 def edit(self, with_valid=True):
1162 if with_valid:
1163 self.is_valid(raise_exception=True)
1164 tool = QuerySet(Tool).filter(id=self.data.get("id")).first()
1165 if tool is None:
1166 raise AppApiException(500, _("Function does not exist"))
1167 # 删除旧的图片
1168 if tool.icon != "":
1169 QuerySet(File).filter(id=tool.icon.split("/")[-1]).delete()
1170 if self.data.get("image") is None:
1171 tool.icon = ""
1172 else:
1173 meta = {"debug": False}
1174 file_id = uuid.uuid7()
1175 file = File(
1176 id=file_id,
1177 file_name=self.data.get("image").name,
1178 source_type=FileSourceType.TOOL,
1179 source_id=tool.id,
1180 meta=meta,
1181 )
1182 file.save(self.data.get("image").read())
1183
1184 tool.icon = f"./oss/file/{file_id}"
1185 tool.save()
1186
1187 return tool.icon
1188
1189 class InternalTool(serializers.Serializer):
1190 user_id = serializers.UUIDField(required=True, label=_("User ID"))

Callers

nothing calls this directly

Calls 7

is_validMethod · 0.95
saveMethod · 0.95
AppApiExceptionClass · 0.90
FileClass · 0.90
readMethod · 0.80
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected