2022-03-28 17:39:36 +03:00
|
|
|
import orjson as json
|
|
|
|
from izihawa_utils.common import filter_none
|
2022-09-02 18:44:56 +03:00
|
|
|
from summa.proto import index_service_pb2 as index_service_pb
|
2022-03-28 17:39:36 +03:00
|
|
|
|
|
|
|
from .base import BaseAction
|
|
|
|
|
|
|
|
|
2022-09-02 18:44:56 +03:00
|
|
|
class ScimagToIndexOperationBytesAction(BaseAction):
|
|
|
|
async def do(self, item: dict) -> bytes:
|
|
|
|
return index_service_pb.IndexOperation(
|
|
|
|
index_document=index_service_pb.IndexDocumentOperation(
|
|
|
|
document=json.dumps(filter_none(item)),
|
|
|
|
),
|
|
|
|
).SerializeToString()
|
2022-03-28 17:39:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
class ScitechToIndexOperationBytesAction(BaseAction):
|
|
|
|
restricted_column_set = [
|
|
|
|
'extension',
|
|
|
|
'fiction_id',
|
|
|
|
'filesize',
|
|
|
|
'has_duplicates',
|
|
|
|
'ipfs_multihashes',
|
|
|
|
'libgen_id',
|
|
|
|
'md5',
|
|
|
|
'original_id',
|
|
|
|
]
|
|
|
|
|
|
|
|
async def do(self, item: dict) -> bytes:
|
|
|
|
# if item['original_id'] is not None:
|
|
|
|
# item = {rc: item[rc] for rc in self.restricted_column_set}
|
2022-09-02 18:44:56 +03:00
|
|
|
return index_service_pb.IndexOperation(
|
|
|
|
index_document=index_service_pb.IndexDocumentOperation(
|
2022-03-28 17:39:36 +03:00
|
|
|
document=json.dumps(filter_none(item)),
|
|
|
|
),
|
|
|
|
).SerializeToString()
|