Skip to content

Commit

Permalink
feat(webui): server side downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 13, 2021
1 parent 398ad5b commit 983c374
Show file tree
Hide file tree
Showing 19 changed files with 444 additions and 433 deletions.
5 changes: 3 additions & 2 deletions packages/plugin-webui/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { ref, watch, reactive, Ref, Component } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import type { User } from 'koishi-core'
import type { Registry, Profile, Meta, Statistics } from '~/server'
import type { Registry, Profile, Meta, Statistics, Awesome } from '~/server'
import * as client from '~/client'

export const views: Component[] = []
Expand Down Expand Up @@ -74,7 +74,8 @@ export const user = storage.create<User>('user')
export const config = storage.create<Config>('config', { authType: 0 }, true)
export const meta = ref<Meta.Payload>(null)
export const profile = ref<Profile.Payload>(null)
export const registry = ref<Registry.Payload>(null)
export const awesome = ref<Awesome.PackageData[]>(null)
export const registry = ref<Registry.PluginData[]>(null)
export const stats = ref<Statistics.Payload>(null)
export const socket = ref<WebSocket>(null)

Expand Down
7 changes: 4 additions & 3 deletions packages/plugin-webui/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ router.addRoute({
})

router.addRoute({
path: '/dependencies',
path: '/awesome',
name: '依赖',
meta: { icon: 'puzzle-piece', authority: 4, require: ['registry'] },
component: () => import('./views/dependencies/index.vue'),
meta: { icon: 'puzzle-piece', authority: 4, require: ['awesome'] },
component: () => import('./views/awesome/index.vue'),
})

router.addRoute({
Expand Down Expand Up @@ -91,6 +91,7 @@ router.afterEach((route) => {
})

receive('meta', data => client.meta.value = data)
receive('awesome', data => client.awesome.value = data)
receive('profile', data => client.profile.value = data)
receive('registry', data => client.registry.value = data)
receive('stats', data => client.stats.value = data)
Expand Down
22 changes: 22 additions & 0 deletions packages/plugin-webui/client/views/awesome/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<k-card class="page-awesome" title="依赖管理">
<table>
<tr>
<th>模块名称</th>
<th>当前版本</th>
<th>最新版本</th>
<th>总体积</th>
<th>综合评分</th>
<th class="operation">操作</th>
</tr>
<package-view v-for="data in awesome" :data="data"/>
</table>
</k-card>
</template>

<script setup lang="ts">
import PackageView from './package.vue'
import { awesome } from '~/client'
</script>
106 changes: 106 additions & 0 deletions packages/plugin-webui/client/views/awesome/package.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<template>
<tr :class="{ workspace: data.local?.isWorkspace }">
<td class="package" :class="data.local ? data.local.isInstalled ? 'active' : 'local' : 'remote'">
<div>
<a
:href="'http://npmjs.com/package/' + data.name"
target="blank" rel="noopener noreferrer"
>{{ data.name.replace('koishi-plugin-', '') }}</a>
<k-badge type="success" v-if="data.official">官方</k-badge>
<k-badge type="warning" v-if="hasUpdate">可更新</k-badge>
</div>
<div class="description">
{{ data.description }}
</div>
</td>
<td class="version">{{ data.local ? data.local.version : '-' }}</td>
<td class="latest">{{ data.version }}</td>
<td class="size">{{ formatSize(data.size) }}</td>
<td class="score">{{ +data.score.final.toFixed(2) }}</td>
<td class="operation">
<k-button frameless v-if="hasUpdate || !data.local"
>{{ data.local ? '更新' : '下载' }}</k-button>
</td>
</tr>
</template>

<script lang="ts" setup>
import type { Awesome } from '~/server'
import { defineProps, computed } from 'vue'
const props = defineProps<{ data: Awesome.PackageData }>()
const hasUpdate = computed(() => {
const { local, version } = props.data
return local && !local.isWorkspace && local.version !== version
})
function formatSize(size: number) {
if (size >= 1024000) {
return Math.round(size / 1048576) + ' MB'
} else {
return Math.round(size / 1024) + ' KB'
}
}
</script>

<style lang="scss">
@import '~/variables';
.package {
text-align: left;
padding-left: 3rem;
position: relative;
a {
font-weight: bold;
transition: 0.3s ease;
color: rgba(244, 244, 245, 0.75);
}
a:hover {
color: rgba(244, 244, 245);
}
.description {
margin-top: 0.15rem;
font-size: 0.9rem;
}
&::before {
content: "";
position: absolute;
border-radius: 100%;
width: 0.5rem;
height: 0.5rem;
top: 50%;
left: 1.25rem;
transform: translateY(-50%);
box-shadow: 1px 1px 2px #3333;
}
&.active::before {
background: $success;
}
&.local::before {
background: $warning;
}
&.remote::before {
background: #eeeeee5f;
}
}
.page-awesome td:not(.package) {
min-width: 4rem;
}
tr.workspace {
.latest, .size {
color: rgba(244, 244, 245, .25);
}
}
</style>
81 changes: 0 additions & 81 deletions packages/plugin-webui/client/views/dependencies/dep-view.vue

This file was deleted.

23 changes: 0 additions & 23 deletions packages/plugin-webui/client/views/dependencies/index.vue

This file was deleted.

80 changes: 0 additions & 80 deletions packages/plugin-webui/client/views/dependencies/manager.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/plugin-webui/client/views/plugins/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<span class="operation">操作</span>
</div>
<div class="plugin-list root">
<plugin-view :data="data" v-for="(data) in registry.plugins"/>
<plugin-view :data="data" v-for="data in registry"/>
</div>
</k-card>
</template>

<script setup lang="ts">
import PluginView from './plugin-view.vue'
import PluginView from './plugin.vue'
import { registry, user } from '~/client'
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
</div>
</template>

<script setup lang="ts">
<script lang="ts" setup>
import type { Registry } from '~/server'
import { send, user } from '~/client'
import { ref, defineProps } from 'vue'
import PluginView from './plugin-view.vue'
import PluginView from './plugin.vue'
const show = ref(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Database, Logger, Time } from 'koishi-core'
import { RECENT_LENGTH, StatRecord, Synchronizer } from '../payload/stats'
import type MongoDatabase from 'koishi-plugin-mongo'
import { RECENT_LENGTH, StatRecord, Synchronizer } from './stats'

const logger = new Logger('status')

Expand Down
Loading

0 comments on commit 983c374

Please sign in to comment.