2024-10-19 15:20:09 +08:00
|
|
|
import type { Fetcher } from 'swr'
|
2024-11-08 16:11:19 +08:00
|
|
|
import { get, getMarketplace, post, upload } from './base'
|
2024-10-19 15:20:09 +08:00
|
|
|
import type {
|
2024-10-22 13:43:01 +08:00
|
|
|
InstallPackageResponse,
|
2024-10-29 17:18:23 +08:00
|
|
|
Permissions,
|
2024-10-25 16:46:02 +08:00
|
|
|
PluginDeclaration,
|
2024-10-29 16:33:27 +08:00
|
|
|
PluginManifestInMarket,
|
2024-10-31 16:27:05 +08:00
|
|
|
PluginTasksResponse,
|
2024-10-25 16:46:02 +08:00
|
|
|
TaskStatusResponse,
|
2024-10-31 16:20:25 +08:00
|
|
|
UninstallPluginResponse,
|
2024-11-13 10:38:56 +08:00
|
|
|
updatePackageResponse,
|
2024-11-01 14:55:56 +08:00
|
|
|
uploadGitHubResponse,
|
2024-10-19 15:20:09 +08:00
|
|
|
} from '@/app/components/plugins/types'
|
2024-10-25 11:15:32 +08:00
|
|
|
import type {
|
|
|
|
MarketplaceCollectionPluginsResponse,
|
|
|
|
MarketplaceCollectionsResponse,
|
|
|
|
} from '@/app/components/plugins/marketplace/types'
|
2024-10-19 15:20:09 +08:00
|
|
|
|
2024-10-24 17:14:17 +08:00
|
|
|
export const uploadPackageFile = async (file: File) => {
|
|
|
|
const formData = new FormData()
|
|
|
|
formData.append('pkg', file)
|
|
|
|
return upload({
|
|
|
|
xhr: new XMLHttpRequest(),
|
|
|
|
data: formData,
|
|
|
|
}, false, '/workspaces/current/plugin/upload/pkg')
|
|
|
|
}
|
2024-10-24 17:24:46 +08:00
|
|
|
|
2024-11-05 16:47:09 +08:00
|
|
|
export const updateFromMarketPlace = async (body: Record<string, string>) => {
|
|
|
|
return post<InstallPackageResponse>('/workspaces/current/plugin/upgrade/marketplace', {
|
|
|
|
body,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-11-13 10:38:56 +08:00
|
|
|
export const updateFromGitHub = async (repoUrl: string, selectedVersion: string, selectedPackage: string,
|
|
|
|
originalPlugin: string, newPlugin: string) => {
|
|
|
|
return post<updatePackageResponse>('/workspaces/current/plugin/upgrade/github', {
|
|
|
|
body: {
|
|
|
|
repo: repoUrl,
|
|
|
|
version: selectedVersion,
|
|
|
|
package: selectedPackage,
|
|
|
|
original_plugin_unique_identifier: originalPlugin,
|
|
|
|
new_plugin_unique_identifier: newPlugin,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-11-01 14:55:56 +08:00
|
|
|
export const uploadGitHub = async (repoUrl: string, selectedVersion: string, selectedPackage: string) => {
|
|
|
|
return post<uploadGitHubResponse>('/workspaces/current/plugin/upload/github', {
|
|
|
|
body: {
|
|
|
|
repo: repoUrl,
|
|
|
|
version: selectedVersion,
|
|
|
|
package: selectedPackage,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-10-29 11:47:14 +08:00
|
|
|
export const fetchIcon = (tenantId: string, fileName: string) => {
|
|
|
|
return get(`workspaces/current/plugin/icon?tenant_id=${tenantId}&filename=${fileName}`)
|
|
|
|
}
|
|
|
|
|
2024-10-25 16:46:02 +08:00
|
|
|
export const fetchManifest = async (uniqueIdentifier: string) => {
|
|
|
|
return get<PluginDeclaration>(`/workspaces/current/plugin/fetch-manifest?plugin_unique_identifier=${uniqueIdentifier}`)
|
|
|
|
}
|
|
|
|
|
2024-10-29 14:53:14 +08:00
|
|
|
export const fetchManifestFromMarketPlace = async (uniqueIdentifier: string) => {
|
2024-10-29 16:33:27 +08:00
|
|
|
return getMarketplace<{ data: { plugin: PluginManifestInMarket } }>(`/plugins/identifier?unique_identifier=${uniqueIdentifier}`)
|
2024-10-29 14:53:14 +08:00
|
|
|
}
|
|
|
|
|
2024-10-25 11:15:32 +08:00
|
|
|
export const fetchMarketplaceCollections: Fetcher<MarketplaceCollectionsResponse, { url: string; }> = ({ url }) => {
|
|
|
|
return get<MarketplaceCollectionsResponse>(url)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchMarketplaceCollectionPlugins: Fetcher<MarketplaceCollectionPluginsResponse, { url: string }> = ({ url }) => {
|
|
|
|
return get<MarketplaceCollectionPluginsResponse>(url)
|
|
|
|
}
|
2024-10-25 16:46:02 +08:00
|
|
|
|
2024-10-31 16:27:05 +08:00
|
|
|
export const fetchPluginTasks = async () => {
|
|
|
|
return get<PluginTasksResponse>('/workspaces/current/plugin/tasks?page=1&page_size=255')
|
|
|
|
}
|
|
|
|
|
2024-10-25 16:46:02 +08:00
|
|
|
export const checkTaskStatus = async (taskId: string) => {
|
|
|
|
return get<TaskStatusResponse>(`/workspaces/current/plugin/tasks/${taskId}`)
|
|
|
|
}
|
2024-10-29 17:18:23 +08:00
|
|
|
|
|
|
|
export const updatePermission = async (permissions: Permissions) => {
|
|
|
|
return post('/workspaces/current/plugin/permission/change', { body: permissions })
|
|
|
|
}
|
2024-10-31 16:20:25 +08:00
|
|
|
|
|
|
|
export const uninstallPlugin = async (pluginId: string) => {
|
|
|
|
return post<UninstallPluginResponse>('/workspaces/current/plugin/uninstall', { body: { plugin_installation_id: pluginId } })
|
|
|
|
}
|