Skip to content

Commit

Permalink
feat: add new apis (#4)
Browse files Browse the repository at this point in the history
* feat: add new apis upload-dataset & create-folder

* feat: move header into params

* feat: update form params

* feat: Add v1.1 APIs

* feat: modify the endpoint of annotation apis

* feat: Write the APIs to 80%

* fix: type error

* chore: fix a typo

* feat: hidden params

* refine: APIs' contents

* chore: fix dependencies version

* chore: fix version again

* refine: Add more comments

* feat: response schema

* chore: rename

* feat: result styles

* refine: Add response status table

* feat: improve ssr compat

* refine: Some fields

* fix: BUGs

* feat: Add response code 5523

* chore: update vue-json-pretty

* chore: add npm registry

* chore: exclude optimize deps

* fix: align apis

* fix: response codes typo

* chore: optimize default theme

---------

Co-authored-by: zhaozhimeng <[email protected]>
Co-authored-by: F-loat <[email protected]>
  • Loading branch information
3 people authored Jul 25, 2024
1 parent d23ba69 commit 0af9476
Show file tree
Hide file tree
Showing 32 changed files with 1,186 additions and 235 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ node_modules/
.DS_Store

.idea
*.mts.timestamp*
package-lock.json
3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
lockfile=false
registry=https://registry.npmmirror.com/
lockfile=false
19 changes: 18 additions & 1 deletion .vitepress/config/en.mts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,35 @@ export const en = defineConfig({
text: 'Authentication',
link: '/overview/authentication'
},
{ text: 'Errors', link: '/overview/errors' },
{ text: 'Response Codes', link: '/overview/response-codes' },
{ text: 'Data Structure', link: '/overview/data-structure' }
]
},
{
text: 'PROJECTS',
items: [
getApiConfig('/projects/create-folder'),
getApiConfig('/projects/create-project'),
getApiConfig('/projects/list-project'),
getApiConfig('/projects/get-project-info')
]
},
{
text: 'DATASETS',
items: [
getApiConfig('/datasets/sync-upload'),
getApiConfig('/datasets/async-import'),
getApiConfig('/datasets/get-status')
]
},
{
text: 'ANNOTATIONS',
items: [
getApiConfig('/annotations/create-workflow'),
getApiConfig('/annotations/request-annotation'),
getApiConfig('/annotations/run-stat')
]
},
{
text: 'TASKS',
items: [
Expand Down
3 changes: 2 additions & 1 deletion .vitepress/config/routes.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export const redirectRouteMap = {
'/reference/send-task': '/tasks/send-task',
'/reference/data-structure': '/overview/data-structure',
'/reference/authentication': '/overview/authentication',
'/reference/create-project': '/projects/create-project'
'/reference/create-project': '/projects/create-project',
'/overview/errors': '/overview/response-codes'
}
55 changes: 48 additions & 7 deletions .vitepress/config/shared.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { defineConfig } from 'vitepress'
import Container from 'markdown-it-container'
import topLevelAwait from 'vite-plugin-top-level-await'
import { viteStaticCopy } from 'vite-plugin-static-copy'
import vueJsx from '@vitejs/plugin-vue-jsx'

interface SidebarItem {
text: string
Expand Down Expand Up @@ -70,7 +71,39 @@ export const shared = defineConfig({
socialLinks: [{ icon: 'github', link: 'https://github.com/stardustai' }]
},
vite: {
resolve: {
alias: [
{
find: 'src/utils',
replacement: 'vue-json-pretty/src/utils'
},
{
find: 'src/components/TreeNode',
replacement: 'vue-json-pretty/src/components/TreeNode'
},
{
find: 'src/components/Brackets',
replacement: 'vue-json-pretty/src/components/Brackets'
},
{
find: 'src/components/CheckController',
replacement: 'vue-json-pretty/src/components/CheckController'
},
{
find: 'src/components/Carets',
replacement: 'vue-json-pretty/src/components/Carets'
},
{
find: '~src/themes.less',
replacement: 'vue-json-pretty/src/themes.less'
}
]
},
optimizeDeps: {
exclude: ['vue-json-pretty']
},
plugins: [
vueJsx(),
topLevelAwait({
promiseExportName: '__tla',
promiseImportName: (i) => `__tla_${i}`
Expand All @@ -91,17 +124,25 @@ export const shared = defineConfig({
},
transformHead() {
return [
[
'script',
{ type: 'text/javascript' },
`(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.setAttribute("data-theme", "dark")})();`
],
[
'script',
{ type: 'text/javascript' },
`(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "n5nncu2bkk");`
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "n5nncu2bkk");`
]
]
},
transformHtml(code) {
return code.replace('<html', '<html data-theme="light"')
},
markdown: {
config: (md) => {
interface Token {
Expand Down Expand Up @@ -130,11 +171,11 @@ export const shared = defineConfig({
}) => string
) => {
return tokens.reduce((rst, token) => {
const { info, content } = token
const content = token.content.replace(/\'/g, '\\"')
const name = token.info.match(/\[(.*)\]/)?.[1] || ''
const [key, type] = name.split(':')
token.content = ''
token.hidden = true
const name = info.match(/\[(.*)\]/)?.[1] || ''
const [key, type] = name.split(':')
return rst + template({ key, type, content })
}, '')
}
Expand Down
47 changes: 32 additions & 15 deletions .vitepress/theme/components/Api/Request/Params/index.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<template>
<div v-if="params">
<h3 v-if="title" class="text-xs font-semibold uppercase">
{{ title }}
{{ title.replaceAll('_', ' ') }}
<span v-if="type" class="opacity-60 ml-0.5">[{{ type }}]</span>
</h3>
<div
class="bg-[var(--vp-sidebar-bg-color)] rounded-lg border border-gray-200 dark:border-[#2e2e32] border-solid my-4 px-2"
>
<div
v-for="([key, item], index) of Object.entries(params)"
v-for="([key, item], index) of Object.entries(params).filter(
([, item]) => !item.hidden
)"
:class="
classnames(
'py-2.5',
Expand Down Expand Up @@ -47,9 +49,9 @@
class="text-xs text-gray-500"
>[{{ item.items.type }}]</span
>
<span v-if="item.default" class="ml-2 text-xs text-gray-500"
>Defaults to {{ item.default }}</span
>
<span v-if="item.default" class="ml-2 text-xs text-gray-500">
Defaults to {{ item.default }}
</span>
</div>
<Input
:type="item.type"
Expand All @@ -63,14 +65,19 @@
@change="(val) => handleChange(key, val)"
/>
</div>
<div v-if="item.description" class="text-xs mt-1">
{{ item.description }}
</div>
<div
v-if="item.description"
class="text-xs mt-1"
v-html="md.renderInline(item.description)"
/>
</div>
</summary>
<div v-if="isComplex(item)" class="daisy-collapse-content -mb-6 px-3">
<api-params v-if="item.type === 'object'" :data="item.properties" />
<api-params v-else :data="item.items.properties" />
<api-params v-if="isObject(item)" :data="item.properties" />
<api-params
v-else-if="isArray(item) && isObject(item.items)"
:data="item.items.properties"
/>
</div>
</details>
</div>
Expand All @@ -86,16 +93,21 @@ export default {

<script setup lang="ts">
import classnames from 'classnames'
import markdownit from 'markdown-it'
import { computed, reactive } from 'vue'
import Input from './Input.vue'
import type { Data } from '../../../../types'
import type { ArrayData, Data, ObjectData } from '../../../../types'
const md = markdownit({
html: true
})
const emit = defineEmits<{
(e: 'change', value?: Record<string, any>): void
}>()
const props = defineProps<{
title: string
title?: string
data?: string | Record<string, Data>
input?: boolean
type?: 'form' | 'json'
Expand All @@ -106,9 +118,14 @@ const params = computed<Record<string, Data>>(() => {
return JSON.parse(decodeURIComponent(props.data))
})
const isComplex = (item: Data) =>
item.type === 'object' ||
(item.type === 'array' && item.items.type === 'object')
const isObject = (item: Data): item is ObjectData => {
return item.type.startsWith('object') && !!item.properties
}
const isArray = (item: Data): item is ArrayData => item.type === 'array'
const isComplex = (item: Data): item is ObjectData | ArrayData => {
return isObject(item) || (isArray(item) && isObject(item.items))
}
const getDefaultValue = (data: Data) => {
if (data.type !== 'file' || !data.default) {
Expand Down
2 changes: 1 addition & 1 deletion .vitepress/theme/components/Api/Request/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const props = defineProps<{
const data = reactive({})
const showInput = ref(false)
const paramKeys = ['body', 'query', 'path', 'form']
const paramKeys = ['path', 'query', 'body']
const handleToggle = (open) => {
showInput.value = open
Expand Down
24 changes: 10 additions & 14 deletions .vitepress/theme/components/Api/Result/Example.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<template>
<div v-if="data">
<h3 class="text-xs font-semibold uppercase">{{ title }}</h3>
<h3 class="text-xs font-semibold uppercase">
{{ title.replaceAll('_', ' ') }}
</h3>
<div
class="bg-[var(--vp-sidebar-bg-color)] rounded-lg border border-gray-200 dark:border-gray-900 border-solid my-4"
>
Expand All @@ -23,14 +25,12 @@
{{ code }}
</div>
<div class="p-2 max-h-[320px] overflow-auto">
<ClientOnly>
<vue-json-pretty
showIcon
:deep="1"
:data="item"
:theme="isDark ? 'dark' : 'light'"
/>
</ClientOnly>
<vue-json-pretty
showIcon
:deep="2"
:data="item"
:theme="isDark ? 'dark' : 'light'"
/>
</div>
</div>
</div>
Expand All @@ -40,7 +40,7 @@
<script setup lang="ts">
import classnames from 'classnames'
import { useData } from 'vitepress'
import VueJsonPretty from 'vue-json-pretty'
import VueJsonPretty from 'vue-json-pretty/src'
defineProps<{
title?: string
Expand All @@ -49,7 +49,3 @@ defineProps<{
const { isDark } = useData()
</script>

<style>
@import url('vue-json-pretty/lib/styles.css');
</style>
55 changes: 0 additions & 55 deletions .vitepress/theme/components/Api/Results.vue

This file was deleted.

7 changes: 4 additions & 3 deletions .vitepress/theme/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
interface Common {
description?: string
required?: boolean
hidden?: boolean
default?: string
required?: boolean
description?: string
}

interface BaseData extends Common {
type: 'string' | 'integer' | 'long' | 'number' | 'boolean' | 'null' | 'file'
}

export interface ObjectData extends Common {
type: 'object'
type: 'object | object[]'
properties: {
[key: string]: Data
}
Expand Down
Loading

0 comments on commit 0af9476

Please sign in to comment.