|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING, AsyncGenerator
|
|
|
|
|
from typing import TYPE_CHECKING, AsyncGenerator, override
|
|
|
|
|
|
|
|
|
|
from mipac.abstract.action import AbstractAction
|
|
|
|
|
from mipac.http import HTTPClient, Route
|
|
|
|
@ -14,9 +14,8 @@ if TYPE_CHECKING:
|
|
|
|
|
from mipac.manager.client import ClientManager
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClientClipActions(AbstractAction):
|
|
|
|
|
def __init__(self, *, clip_id: str | None = None, session: HTTPClient, client: ClientManager):
|
|
|
|
|
self._clip_id = clip_id
|
|
|
|
|
class SharedClipActions(AbstractAction):
|
|
|
|
|
def __init__(self, *, session: HTTPClient, client: ClientManager):
|
|
|
|
|
self._session = session
|
|
|
|
|
self._client = client
|
|
|
|
|
|
|
|
|
@ -26,8 +25,9 @@ class ClientClipActions(AbstractAction):
|
|
|
|
|
since_id: str | None = None,
|
|
|
|
|
until_id: str | None = None,
|
|
|
|
|
get_all: bool = False,
|
|
|
|
|
*,
|
|
|
|
|
clip_id: str | None = None,
|
|
|
|
|
) -> AsyncGenerator[Note, None]:
|
|
|
|
|
) -> AsyncGenerator[Note, None]: # TODO: 作り直し
|
|
|
|
|
"""Get notes from a clip
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
@ -47,12 +47,6 @@ class ClientClipActions(AbstractAction):
|
|
|
|
|
AsyncGenerator[Note, None]
|
|
|
|
|
The notes
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
clip_id = self._clip_id or clip_id
|
|
|
|
|
|
|
|
|
|
if clip_id is None:
|
|
|
|
|
raise ValueError("clip_id is required")
|
|
|
|
|
|
|
|
|
|
if limit > 100:
|
|
|
|
|
raise ValueError("limit must be less than 100")
|
|
|
|
|
|
|
|
|
@ -73,7 +67,7 @@ class ClientClipActions(AbstractAction):
|
|
|
|
|
if get_all is False or pagination.is_final:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
async def add_note(self, note_id: str, clip_id: str | None = None) -> bool:
|
|
|
|
|
async def add_note(self, note_id: str, *, clip_id: str) -> bool:
|
|
|
|
|
"""Add a note to a clip
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
@ -88,18 +82,13 @@ class ClientClipActions(AbstractAction):
|
|
|
|
|
bool
|
|
|
|
|
True if the note was added to the clip, False otherwise
|
|
|
|
|
"""
|
|
|
|
|
clip_id = self._clip_id or clip_id
|
|
|
|
|
|
|
|
|
|
if clip_id is None:
|
|
|
|
|
raise ValueError("clip_id is required")
|
|
|
|
|
|
|
|
|
|
body = {"clipId": clip_id, "noteId": note_id}
|
|
|
|
|
result: bool = await self._session.request(
|
|
|
|
|
Route("POST", "/api/clips/add-note"), json=body, auth=True
|
|
|
|
|
)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
async def remove_note(self, note_id: str, clip_id: str | None) -> bool:
|
|
|
|
|
async def remove_note(self, note_id: str, *, clip_id: str) -> bool:
|
|
|
|
|
"""Remove a note from a clip
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
@ -114,18 +103,13 @@ class ClientClipActions(AbstractAction):
|
|
|
|
|
bool
|
|
|
|
|
True if the note was removed from the clip, False otherwise
|
|
|
|
|
"""
|
|
|
|
|
clip_id = self._clip_id or clip_id
|
|
|
|
|
|
|
|
|
|
if clip_id is None:
|
|
|
|
|
raise ValueError("clip_id is required")
|
|
|
|
|
|
|
|
|
|
body = {"clipId": clip_id, "noteId": note_id}
|
|
|
|
|
result: bool = await self._session.request(
|
|
|
|
|
Route("POST", "/api/clips/remove-note"), json=body, auth=True
|
|
|
|
|
)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
async def delete(self, clip_id: str | None = None) -> bool:
|
|
|
|
|
async def delete(self, *, clip_id: str) -> bool:
|
|
|
|
|
"""Delete a clip
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
@ -138,11 +122,6 @@ class ClientClipActions(AbstractAction):
|
|
|
|
|
bool
|
|
|
|
|
True if the clip was deleted, False otherwise
|
|
|
|
|
"""
|
|
|
|
|
clip_id = self._clip_id or clip_id
|
|
|
|
|
|
|
|
|
|
if clip_id is None:
|
|
|
|
|
raise ValueError("clip_id is required")
|
|
|
|
|
|
|
|
|
|
body = {"clipId": clip_id}
|
|
|
|
|
result: bool = await self._session.request(
|
|
|
|
|
Route("POST", "/api/clips/delete"), json=body, auth=True
|
|
|
|
@ -154,7 +133,8 @@ class ClientClipActions(AbstractAction):
|
|
|
|
|
name: str,
|
|
|
|
|
is_public: bool | None = None,
|
|
|
|
|
description: str | None = None,
|
|
|
|
|
clip_id: str | None = None,
|
|
|
|
|
*,
|
|
|
|
|
clip_id: str,
|
|
|
|
|
) -> Clip:
|
|
|
|
|
"""Update a clip
|
|
|
|
|
|
|
|
|
@ -175,11 +155,6 @@ class ClientClipActions(AbstractAction):
|
|
|
|
|
True if the clip was updated, False otherwise
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
clip_id = self._clip_id or clip_id
|
|
|
|
|
|
|
|
|
|
if clip_id is None:
|
|
|
|
|
raise ValueError("clip_id is required")
|
|
|
|
|
|
|
|
|
|
body = {"clipId": clip_id, "name": name, "isPublic": is_public, "description": description}
|
|
|
|
|
result: IClip = await self._session.request(
|
|
|
|
|
Route("POST", "/api/clips/update"), json=body, auth=True
|
|
|
|
@ -187,9 +162,138 @@ class ClientClipActions(AbstractAction):
|
|
|
|
|
return Clip(result, client=self._client)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClipActions(ClientClipActions):
|
|
|
|
|
def __init__(self, *, clip_id: str | None = None, session: HTTPClient, client: ClientManager):
|
|
|
|
|
super().__init__(clip_id=clip_id, session=session, client=client)
|
|
|
|
|
class ClientClipActions(SharedClipActions): # TODO: 使うようにする
|
|
|
|
|
def __init__(self, clip_id: str, *, session: HTTPClient, client: ClientManager):
|
|
|
|
|
super().__init__(session=session, client=client)
|
|
|
|
|
self._clip_id = clip_id
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
async def get_notes(
|
|
|
|
|
self,
|
|
|
|
|
limit: int = 10,
|
|
|
|
|
since_id: str | None = None,
|
|
|
|
|
until_id: str | None = None,
|
|
|
|
|
get_all: bool = False,
|
|
|
|
|
*,
|
|
|
|
|
clip_id: str | None = None,
|
|
|
|
|
) -> AsyncGenerator[Note, None]:
|
|
|
|
|
"""Get notes from a clip
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
clip_id : str | None, optional, by default None
|
|
|
|
|
The clip id
|
|
|
|
|
limit : int, optional, by default 10
|
|
|
|
|
The number of notes to get
|
|
|
|
|
since_id : str | None, optional, by default None
|
|
|
|
|
The note id to get notes after
|
|
|
|
|
until_id : str | None, optional, by default None
|
|
|
|
|
The note id to get notes before
|
|
|
|
|
get_all : bool, optional, by default False
|
|
|
|
|
Whether to get all notes
|
|
|
|
|
|
|
|
|
|
Yields
|
|
|
|
|
------
|
|
|
|
|
AsyncGenerator[Note, None]
|
|
|
|
|
The notes
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
clip_id = clip_id or self._clip_id
|
|
|
|
|
|
|
|
|
|
async for note in super().get_notes(
|
|
|
|
|
limit=limit, since_id=since_id, until_id=until_id, get_all=get_all, clip_id=clip_id
|
|
|
|
|
):
|
|
|
|
|
yield note
|
|
|
|
|
|
|
|
|
|
async def add_note(self, note_id: str, clip_id: str | None = None) -> bool:
|
|
|
|
|
"""Add a note to a clip
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
clip_id : str | None, optional, by default None
|
|
|
|
|
The clip id
|
|
|
|
|
note_id : str
|
|
|
|
|
The note id
|
|
|
|
|
|
|
|
|
|
Returns
|
|
|
|
|
-------
|
|
|
|
|
bool
|
|
|
|
|
True if the note was added to the clip, False otherwise
|
|
|
|
|
"""
|
|
|
|
|
clip_id = clip_id or self._clip_id
|
|
|
|
|
|
|
|
|
|
return await super().add_note(note_id=note_id, clip_id=clip_id)
|
|
|
|
|
|
|
|
|
|
async def remove_note(self, note_id: str, clip_id: str | None) -> bool:
|
|
|
|
|
"""Remove a note from a clip
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
clip_id : str | None, optional, by default None
|
|
|
|
|
The clip id
|
|
|
|
|
note_id : str
|
|
|
|
|
The note id
|
|
|
|
|
|
|
|
|
|
Returns
|
|
|
|
|
-------
|
|
|
|
|
bool
|
|
|
|
|
True if the note was removed from the clip, False otherwise
|
|
|
|
|
"""
|
|
|
|
|
clip_id = clip_id or self._clip_id
|
|
|
|
|
|
|
|
|
|
return await super().remove_note(note_id=note_id, clip_id=clip_id)
|
|
|
|
|
|
|
|
|
|
async def delete(self, clip_id: str | None = None) -> bool:
|
|
|
|
|
"""Delete a clip
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
clip_id : str | None, optional, by default None
|
|
|
|
|
The clip id
|
|
|
|
|
|
|
|
|
|
Returns
|
|
|
|
|
-------
|
|
|
|
|
bool
|
|
|
|
|
True if the clip was deleted, False otherwise
|
|
|
|
|
"""
|
|
|
|
|
clip_id = clip_id or self._clip_id
|
|
|
|
|
|
|
|
|
|
return await super().delete(clip_id=clip_id)
|
|
|
|
|
|
|
|
|
|
async def update(
|
|
|
|
|
self,
|
|
|
|
|
name: str,
|
|
|
|
|
is_public: bool | None = None,
|
|
|
|
|
description: str | None = None,
|
|
|
|
|
clip_id: str | None = None,
|
|
|
|
|
) -> Clip:
|
|
|
|
|
"""Update a clip
|
|
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
|
----------
|
|
|
|
|
clip_id : str | None, optional, by default None
|
|
|
|
|
The clip id
|
|
|
|
|
name : str
|
|
|
|
|
The clip name
|
|
|
|
|
is_public : bool, optional
|
|
|
|
|
Whether the clip is public, by default None
|
|
|
|
|
description : str, optional
|
|
|
|
|
The clip description, by default None
|
|
|
|
|
|
|
|
|
|
Returns
|
|
|
|
|
-------
|
|
|
|
|
bool
|
|
|
|
|
True if the clip was updated, False otherwise
|
|
|
|
|
"""
|
|
|
|
|
clip_id = clip_id or self._clip_id
|
|
|
|
|
|
|
|
|
|
return await super().update(
|
|
|
|
|
name=name, is_public=is_public, description=description, clip_id=clip_id
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClipActions(SharedClipActions):
|
|
|
|
|
def __init__(self, *, session: HTTPClient, client: ClientManager):
|
|
|
|
|
super().__init__(session=session, client=client)
|
|
|
|
|
|
|
|
|
|
async def get_my_favorites(self):
|
|
|
|
|
"""Get my favorite clips
|
|
|
|
|