feat(online_driver): add online driver plugin, support browsing and downloading
parent
efccbe4039
commit
eee72101f4
@ -0,0 +1,73 @@
|
|||||||
|
from collections.abc import Generator
|
||||||
|
|
||||||
|
from core.datasource.__base.datasource_plugin import DatasourcePlugin
|
||||||
|
from core.datasource.__base.datasource_runtime import DatasourceRuntime
|
||||||
|
from core.datasource.entities.datasource_entities import (
|
||||||
|
DatasourceEntity,
|
||||||
|
DatasourceMessage,
|
||||||
|
DatasourceProviderType,
|
||||||
|
OnlineDriverBrowseFilesRequest,
|
||||||
|
OnlineDriverBrowseFilesResponse,
|
||||||
|
OnlineDriverDownloadFileRequest,
|
||||||
|
)
|
||||||
|
from core.plugin.impl.datasource import PluginDatasourceManager
|
||||||
|
|
||||||
|
|
||||||
|
class OnlineDriverDatasourcePlugin(DatasourcePlugin):
|
||||||
|
tenant_id: str
|
||||||
|
icon: str
|
||||||
|
plugin_unique_identifier: str
|
||||||
|
entity: DatasourceEntity
|
||||||
|
runtime: DatasourceRuntime
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
entity: DatasourceEntity,
|
||||||
|
runtime: DatasourceRuntime,
|
||||||
|
tenant_id: str,
|
||||||
|
icon: str,
|
||||||
|
plugin_unique_identifier: str,
|
||||||
|
) -> None:
|
||||||
|
super().__init__(entity, runtime)
|
||||||
|
self.tenant_id = tenant_id
|
||||||
|
self.icon = icon
|
||||||
|
self.plugin_unique_identifier = plugin_unique_identifier
|
||||||
|
|
||||||
|
def online_driver_browse_files(
|
||||||
|
self,
|
||||||
|
user_id: str,
|
||||||
|
request: OnlineDriverBrowseFilesRequest,
|
||||||
|
provider_type: str,
|
||||||
|
) -> Generator[OnlineDriverBrowseFilesResponse, None, None]:
|
||||||
|
manager = PluginDatasourceManager()
|
||||||
|
|
||||||
|
return manager.online_driver_browse_files(
|
||||||
|
tenant_id=self.tenant_id,
|
||||||
|
user_id=user_id,
|
||||||
|
datasource_provider=self.entity.identity.provider,
|
||||||
|
datasource_name=self.entity.identity.name,
|
||||||
|
credentials=self.runtime.credentials,
|
||||||
|
request=request,
|
||||||
|
provider_type=provider_type,
|
||||||
|
)
|
||||||
|
|
||||||
|
def online_driver_download_file(
|
||||||
|
self,
|
||||||
|
user_id: str,
|
||||||
|
request: OnlineDriverDownloadFileRequest,
|
||||||
|
provider_type: str,
|
||||||
|
) -> Generator[DatasourceMessage, None, None]:
|
||||||
|
manager = PluginDatasourceManager()
|
||||||
|
|
||||||
|
return manager.online_driver_download_file(
|
||||||
|
tenant_id=self.tenant_id,
|
||||||
|
user_id=user_id,
|
||||||
|
datasource_provider=self.entity.identity.provider,
|
||||||
|
datasource_name=self.entity.identity.name,
|
||||||
|
credentials=self.runtime.credentials,
|
||||||
|
request=request,
|
||||||
|
provider_type=provider_type,
|
||||||
|
)
|
||||||
|
|
||||||
|
def datasource_provider_type(self) -> str:
|
||||||
|
return DatasourceProviderType.ONLINE_DRIVER
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
from core.datasource.__base.datasource_provider import DatasourcePluginProviderController
|
||||||
|
from core.datasource.__base.datasource_runtime import DatasourceRuntime
|
||||||
|
from core.datasource.entities.datasource_entities import DatasourceProviderEntityWithPlugin, DatasourceProviderType
|
||||||
|
from core.datasource.online_driver.online_driver_plugin import OnlineDriverDatasourcePlugin
|
||||||
|
|
||||||
|
|
||||||
|
class OnlineDriverDatasourcePluginProviderController(DatasourcePluginProviderController):
|
||||||
|
entity: DatasourceProviderEntityWithPlugin
|
||||||
|
plugin_id: str
|
||||||
|
plugin_unique_identifier: str
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, entity: DatasourceProviderEntityWithPlugin, plugin_id: str, plugin_unique_identifier: str, tenant_id: str
|
||||||
|
) -> None:
|
||||||
|
super().__init__(entity, tenant_id)
|
||||||
|
self.plugin_id = plugin_id
|
||||||
|
self.plugin_unique_identifier = plugin_unique_identifier
|
||||||
|
|
||||||
|
@property
|
||||||
|
def provider_type(self) -> DatasourceProviderType:
|
||||||
|
"""
|
||||||
|
returns the type of the provider
|
||||||
|
"""
|
||||||
|
return DatasourceProviderType.ONLINE_DRIVER
|
||||||
|
|
||||||
|
def get_datasource(self, datasource_name: str) -> OnlineDriverDatasourcePlugin: # type: ignore
|
||||||
|
"""
|
||||||
|
return datasource with given name
|
||||||
|
"""
|
||||||
|
datasource_entity = next(
|
||||||
|
(
|
||||||
|
datasource_entity
|
||||||
|
for datasource_entity in self.entity.datasources
|
||||||
|
if datasource_entity.identity.name == datasource_name
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
|
||||||
|
if not datasource_entity:
|
||||||
|
raise ValueError(f"Datasource with name {datasource_name} not found")
|
||||||
|
|
||||||
|
return OnlineDriverDatasourcePlugin(
|
||||||
|
entity=datasource_entity,
|
||||||
|
runtime=DatasourceRuntime(tenant_id=self.tenant_id),
|
||||||
|
tenant_id=self.tenant_id,
|
||||||
|
icon=self.entity.identity.icon,
|
||||||
|
plugin_unique_identifier=self.plugin_unique_identifier,
|
||||||
|
)
|
||||||
Loading…
Reference in New Issue