diff --git a/back/src/Kyoo.Core/Views/Helper/CrudApi.cs b/back/src/Kyoo.Core/Views/Helper/CrudApi.cs index ae389f95..44e4447f 100644 --- a/back/src/Kyoo.Core/Views/Helper/CrudApi.cs +++ b/back/src/Kyoo.Core/Views/Helper/CrudApi.cs @@ -170,6 +170,33 @@ public class CrudApi : BaseApi return await Repository.Edit(resource); } + /// + /// Edit + /// + /// + /// Edit an item. If the ID is specified it will be used to identify the resource. + /// If not, the slug will be used to identify it. + /// + /// The id or slug of the resource. + /// The resource to edit. + /// The edited resource. + /// The resource in the request body is invalid. + /// No item found with the specified ID (or slug). + [HttpPut("{identifier:id}")] + [PartialPermission(Kind.Write)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(RequestError))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task> Edit(Identifier identifier, [FromBody] T resource) + { + Guid id = await identifier.Match( + id => Task.FromResult(id), + async slug => (await Repository.Get(slug)).Id + ); + resource.Id = id; + return await Repository.Edit(resource); + } + /// /// Patch /// diff --git a/scanner/matcher/subscriber.py b/scanner/matcher/subscriber.py index 103b55bd..728cf5bd 100644 --- a/scanner/matcher/subscriber.py +++ b/scanner/matcher/subscriber.py @@ -43,20 +43,24 @@ class Subscriber: async def listen(self, scanner: Matcher): async def on_message(message: AbstractIncomingMessage): - msg = decoder.decode(message.body) - ack = False - match msg: - case Scan(path): - ack = await scanner.identify(path) - case Delete(path): - ack = await scanner.delete(path) - case Refresh(kind, id): - ack = await scanner.refresh(kind, id) - case _: - logger.error(f"Invalid action: {msg.action}") - if ack: - await message.ack() - else: + try: + msg = decoder.decode(message.body) + ack = False + match msg: + case Scan(path): + ack = await scanner.identify(path) + case Delete(path): + ack = await scanner.delete(path) + case Refresh(kind, id): + ack = await scanner.refresh(kind, id) + case _: + logger.error(f"Invalid action: {msg.action}") + if ack: + await message.ack() + else: + await message.reject() + except Exception as e: + logger.exception("Unhandled error", exc_info=e) await message.reject() # Allow up to 20 scan requests to run in parallel on the same listener. diff --git a/scanner/providers/kyoo_client.py b/scanner/providers/kyoo_client.py index a8ef8ccd..b804b740 100644 --- a/scanner/providers/kyoo_client.py +++ b/scanner/providers/kyoo_client.py @@ -177,7 +177,7 @@ class KyooClient: jdkwargs={"indent": 4}, ), ) - async with self.client.post( + async with self.client.put( f"{self._url}/{path}", json=data, headers={"X-API-Key": self._api_key},