@vyr/service-asset 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +21 -0
- package/src/AssetMethodProvider.ts +132 -0
- package/src/AssetService.ts +102 -0
- package/src/index.ts +2 -0
- package/src/locale/Language.ts +10 -0
- package/src/locale/LanguageProvider.ts +15 -0
- package/src/locale/index.ts +2 -0
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vyr/service-asset",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"axios": "^1.7.4",
|
|
10
|
+
"@vyr/locale": "0.0.1",
|
|
11
|
+
"@vyr/declare": "0.0.1",
|
|
12
|
+
"@vyr/service": "0.0.1",
|
|
13
|
+
"@vyr/runtime": "0.0.1",
|
|
14
|
+
"@vyr/engine": "0.0.1",
|
|
15
|
+
"@vyr/service-rpc": "0.0.1"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"package.json",
|
|
19
|
+
"src/"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { ArrayUtils, AsyncTask, Descriptor } from "@vyr/engine"
|
|
2
|
+
import { DataService, runtime } from "@vyr/runtime"
|
|
3
|
+
import { Message, RpcService, VirtualNode } from '@vyr/service-rpc'
|
|
4
|
+
import { AssetService } from "./AssetService"
|
|
5
|
+
|
|
6
|
+
class AssetMethodProvider {
|
|
7
|
+
readonly ready = new AsyncTask()
|
|
8
|
+
readonly service
|
|
9
|
+
|
|
10
|
+
constructor(service: AssetService) {
|
|
11
|
+
this.service = service
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
private _clear(items: Descriptor[], item: VirtualNode) {
|
|
15
|
+
if (items.length === 0) return
|
|
16
|
+
for (const stickupItem of items) {
|
|
17
|
+
if (stickupItem.uuid !== item.uuid) continue
|
|
18
|
+
ArrayUtils.remove(items, stickupItem)
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
listen() {
|
|
24
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
25
|
+
rpcService.listen(Message.rpc.connection.Method, this._connection)
|
|
26
|
+
rpcService.listen(Message.rpc.disconnect.Method, this._disconnect)
|
|
27
|
+
rpcService.listen(Message.asset.initialize.Method, this._initialize)
|
|
28
|
+
rpcService.listen(Message.asset.create.Method, this._create)
|
|
29
|
+
rpcService.listen(Message.asset.delete.Method, this._delete)
|
|
30
|
+
rpcService.listen(Message.asset.add.Method, this._add)
|
|
31
|
+
rpcService.listen(Message.asset.remove.Method, this._remove)
|
|
32
|
+
rpcService.listen(Message.asset.open.Method, this._open)
|
|
33
|
+
rpcService.listen(Message.asset.close.Method, this._close)
|
|
34
|
+
rpcService.listen(Message.asset.update.Method, this._update)
|
|
35
|
+
rpcService.listen(Message.asset.dragdrap.Method, this._dragdrap)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
_connection = async (msg: InstanceType<typeof Message['rpc']['connection']['NoticeMessage']>) => {
|
|
39
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
40
|
+
rpcService.send(new Message.asset.initialize.RequestMessage())
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_disconnect = (msg: InstanceType<typeof Message['rpc']['disconnect']['NoticeMessage']>) => {
|
|
44
|
+
this.service.root.clearUser(msg.params.client)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
_initialize = (msg: InstanceType<typeof Message['asset']['initialize']['NoticeMessage']>) => {
|
|
48
|
+
this.service.root.clear()
|
|
49
|
+
for (const sub of msg.params.root.children) this.service.root.add(new VirtualNode(sub))
|
|
50
|
+
this.ready.run()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_open = (msg: InstanceType<typeof Message['asset']['open']['NoticeMessage']>) => {
|
|
54
|
+
const asset = VirtualNode.get<VirtualNode>(msg.params.url)
|
|
55
|
+
if (asset) asset.addUser(msg.params.client)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_close = (msg: InstanceType<typeof Message['asset']['close']['NoticeMessage']>) => {
|
|
59
|
+
const asset = VirtualNode.get<VirtualNode>(msg.params.url)
|
|
60
|
+
if (asset) asset.removeUser(msg.params.client)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
_create = (msg: InstanceType<typeof Message['asset']['create']['NoticeMessage']>) => {
|
|
64
|
+
const asset = VirtualNode.get<VirtualNode>(msg.params.parent)
|
|
65
|
+
if (asset === null) return
|
|
66
|
+
asset.add(new VirtualNode(VirtualNode.deserialization(msg.params.node)))
|
|
67
|
+
asset.sort()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
_delete = (msg: InstanceType<typeof Message['asset']['delete']['NoticeMessage']>) => {
|
|
71
|
+
const dataService = runtime.get<DataService>('data')
|
|
72
|
+
for (const path of msg.params.urls) {
|
|
73
|
+
const node = VirtualNode.get<VirtualNode>(path)
|
|
74
|
+
if (node === null) return
|
|
75
|
+
const ancestor = node.traceAncestor<VirtualNode>(false)
|
|
76
|
+
if (ancestor.parent === null) continue
|
|
77
|
+
|
|
78
|
+
this._clear(dataService.footer.status.stickupItems, node)
|
|
79
|
+
ancestor.parent.remove(node)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
_add = (msg: InstanceType<typeof Message['asset']['add']['NoticeMessage']>) => {
|
|
84
|
+
const parent = Descriptor.get<Descriptor>(msg.params.parent)
|
|
85
|
+
if (parent === null) return
|
|
86
|
+
|
|
87
|
+
if (msg.params.next) {
|
|
88
|
+
for (const item of msg.params.node) {
|
|
89
|
+
const node = Descriptor.create(item)
|
|
90
|
+
parent.insertBefore(node.uuid, msg.params.next)
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
for (const item of msg.params.node) {
|
|
94
|
+
const node = Descriptor.create(item)
|
|
95
|
+
parent.add(node)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
_remove = (msg: InstanceType<typeof Message['asset']['remove']['NoticeMessage']>) => {
|
|
101
|
+
const dataService = runtime.get<DataService>('data')
|
|
102
|
+
|
|
103
|
+
for (const uuid of msg.params.uuids) {
|
|
104
|
+
const target = Descriptor.get<Descriptor>(uuid)
|
|
105
|
+
if (target === null) continue
|
|
106
|
+
const ancestor = target.traceAncestor(false)
|
|
107
|
+
if (ancestor.parent === null) continue
|
|
108
|
+
ancestor.parent.remove(target)
|
|
109
|
+
|
|
110
|
+
ArrayUtils.removeByKey(this.service.navigator.selectAll, 'uuid', target.uuid)
|
|
111
|
+
ArrayUtils.removeByKey(this.service.navigator.status.stickupItems, 'uuid', target.uuid)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_update = (msg: InstanceType<typeof Message['asset']['update']['NoticeMessage']>) => {
|
|
116
|
+
const descriptor = Descriptor.get<Descriptor>(msg.params.content.uuid)
|
|
117
|
+
if (descriptor) descriptor.syncWith(msg.params.content)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
_dragdrap = (msg: InstanceType<typeof Message['asset']['dragdrap']['NoticeMessage']>) => {
|
|
121
|
+
if (msg.params.url !== this.service.navigator.url) return
|
|
122
|
+
|
|
123
|
+
const method = msg.params.next ? 'insertBefore' : msg.params.type
|
|
124
|
+
const target = msg.params.next || msg.params.targetData.data.uuid
|
|
125
|
+
|
|
126
|
+
for (const uuid of msg.params.dragData.data.uuids) {
|
|
127
|
+
this.service.root[method](uuid, target)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export { AssetMethodProvider }
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import { Service } from '@vyr/service'
|
|
3
|
+
import { DraggableData, DraggableEndType, } from '@vyr/declare'
|
|
4
|
+
import { runtime, SidebarNavigator } from '@vyr/runtime'
|
|
5
|
+
import { Descriptor, DeserializationObject } from '@vyr/engine'
|
|
6
|
+
import { RpcService, Message, VirtualNode } from '@vyr/service-rpc'
|
|
7
|
+
import { AssetMethodProvider } from "./AssetMethodProvider"
|
|
8
|
+
|
|
9
|
+
class AssetService extends Service {
|
|
10
|
+
private _provider = new AssetMethodProvider(this)
|
|
11
|
+
readonly navigator
|
|
12
|
+
readonly root
|
|
13
|
+
|
|
14
|
+
constructor(name: string, root: VirtualNode, navigator: SidebarNavigator) {
|
|
15
|
+
super(name)
|
|
16
|
+
this.name = name
|
|
17
|
+
this.root = root
|
|
18
|
+
this.navigator = navigator
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async ready() {
|
|
22
|
+
this._provider.listen()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async start() {
|
|
26
|
+
await this._provider.ready.done()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
select(path: string) {
|
|
30
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
31
|
+
rpcService.send(new Message.asset.select.RequestMessage(path))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
open(path: string) {
|
|
35
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
36
|
+
rpcService.send(new Message.asset.open.RequestMessage(path))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
close(path: string) {
|
|
40
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
41
|
+
rpcService.send(new Message.asset.close.RequestMessage(path))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**新增文件 */
|
|
45
|
+
create(fileType: boolean, name: string, suffix: string, parent: string, content: string) {
|
|
46
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
47
|
+
rpcService.send(new Message.asset.create.RequestMessage(fileType, name, suffix, parent, content))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**删除文件 */
|
|
51
|
+
delete(path: string[] | string) {
|
|
52
|
+
const requestData = Array.isArray(path) ? path : [path]
|
|
53
|
+
if (requestData.length === 0) return
|
|
54
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
55
|
+
rpcService.send(new Message.asset.delete.RequestMessage(requestData))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
add(path: string, node: DeserializationObject<Descriptor>[], parent: string) {
|
|
59
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
60
|
+
rpcService.send(new Message.asset.add.RequestMessage(path, parent, node))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
remove(path: string, uuids: string[]) {
|
|
64
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
65
|
+
rpcService.send(new Message.asset.remove.RequestMessage(path, uuids))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
dragdrap(path: string, type: DraggableEndType, dragData: DraggableData<{ uuids: string[] }>, targetData: DraggableData<{ uuid: string }>) {
|
|
69
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
70
|
+
rpcService.send(new Message.asset.dragdrap.RequestMessage(path, type, dragData, targetData))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
rename(path: string, newName: string) {
|
|
74
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
75
|
+
rpcService.send(new Message.asset.rename.RequestMessage(newName, path))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**剪切文件,将文件移动到指定目录 */
|
|
79
|
+
cut(path: string[], target: string) {
|
|
80
|
+
if (path.length === 0) return
|
|
81
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
82
|
+
rpcService.send(new Message.asset.cut.RequestMessage(path, target))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**复制文件 */
|
|
86
|
+
copy(path: string[], target: string) {
|
|
87
|
+
if (path.length === 0) return
|
|
88
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
89
|
+
rpcService.send(new Message.asset.copy.RequestMessage(path, target))
|
|
90
|
+
}
|
|
91
|
+
update(path: string, content: DeserializationObject<Descriptor>) {
|
|
92
|
+
const rpcService = runtime.get<RpcService>('rpc')
|
|
93
|
+
rpcService.send(new Message.asset.update.RequestMessage(path, content))
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async read(url: string) {
|
|
97
|
+
const res = await axios.get<string>(url, { responseType: 'text' })
|
|
98
|
+
return res.data
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { AssetService }
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Locale } from "@vyr/locale";
|
|
2
|
+
import { zhCnLanguageProvider, ZhCNLanguageProvider } from "./LanguageProvider";
|
|
3
|
+
|
|
4
|
+
Locale.register(zhCnLanguageProvider)
|
|
5
|
+
|
|
6
|
+
const language = Locale.getLanguage<ZhCNLanguageProvider>(zhCnLanguageProvider.name)
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
language
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LanguageProvider } from '@vyr/locale'
|
|
2
|
+
|
|
3
|
+
interface ZhCNLanguageProvider extends LanguageProvider {
|
|
4
|
+
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const zhCnLanguageProvider: ZhCNLanguageProvider = {
|
|
8
|
+
id: 'zh_CN',
|
|
9
|
+
name: '@vyr/service-asset',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
ZhCNLanguageProvider,
|
|
14
|
+
zhCnLanguageProvider,
|
|
15
|
+
}
|