1
1
import type { ActionTree } from 'vuex'
2
- import type { FilesState , KlipperFile , KlipperDir , FileChangeSocketResponse , KlipperFileWithMeta , DiskUsage , FileChangeItem , FilePaths } from './types'
2
+ import type { FilesState , MoonrakerFile , MoonrakerDir , FileChange , MoonrakerFileWithMeta , FileChangeItem , FilePaths , DirectoryInformation } from './types'
3
3
import type { RootState } from '../types'
4
4
import getFilePaths from '@/util/get-file-paths'
5
5
import { SocketActions } from '@/api/socketActions'
6
6
import { Globals } from '@/globals'
7
+ import type { ObjectWithRequest } from '@/plugins/socketClient'
7
8
8
- const itemAsKlipperFile = ( item : FileChangeItem , paths : FilePaths ) : KlipperFile => ( {
9
+ const itemAsMoonrakerFile = ( item : FileChangeItem , paths : FilePaths ) : MoonrakerFile => ( {
9
10
filename : paths . filename ,
10
11
modified : item . modified ,
11
12
size : item . size ,
12
13
permissions : item . permissions
13
14
} )
14
15
15
- const itemAsKlipperDir = ( item : FileChangeItem , paths : FilePaths ) : KlipperDir => ( {
16
+ const itemAsMoonrakerDir = ( item : FileChangeItem , paths : FilePaths ) : MoonrakerDir => ( {
16
17
dirname : paths . filename ,
17
18
modified : item . modified ,
18
19
size : item . size ,
@@ -27,9 +28,9 @@ export const actions: ActionTree<FilesState, RootState> = {
27
28
commit ( 'setReset' )
28
29
} ,
29
30
30
- async onServerFilesGetDirectory ( { commit } , payload : { disk_usage : DiskUsage ; files : ( KlipperFile | KlipperFileWithMeta ) [ ] ; dirs : KlipperDir [ ] ; __request__ : any } ) {
31
- const { disk_usage, files, dirs, __request__ : request } = payload
32
- const { path } = request . params
31
+ async onServerFilesGetDirectory ( { commit } , payload : ObjectWithRequest < DirectoryInformation > ) {
32
+ const { disk_usage, files, dirs } = payload
33
+ const { path } = payload . __request__ . params ?? { }
33
34
34
35
const filteredDirs = dirs
35
36
. filter ( file =>
@@ -42,16 +43,16 @@ export const actions: ActionTree<FilesState, RootState> = {
42
43
commit ( 'setServerFilesGetDirectory' , { path, content : { files, dirs : filteredDirs } } )
43
44
} ,
44
45
45
- async onServerFilesListRoot ( { commit } , payload ) {
46
- const { root } = payload . __request__ . params
46
+ async onServerFilesListRoot ( { commit } , payload : ObjectWithRequest < [ ] > ) {
47
+ const { root } = payload . __request__ . params ?? { }
47
48
48
49
commit ( 'setServerFilesListRoot' , { root, files : [ ...payload ] } )
49
50
} ,
50
51
51
52
/**
52
53
* If we request the metadata (a file..) then we load and update here.
53
54
*/
54
- async onFileMetaData ( { commit } , payload : KlipperFileWithMeta ) {
55
+ async onFileMetaData ( { commit } , payload : MoonrakerFileWithMeta ) {
55
56
const paths = getFilePaths ( payload . filename , 'gcodes' )
56
57
57
58
if ( ! paths . filtered ) {
@@ -69,17 +70,17 @@ export const actions: ActionTree<FilesState, RootState> = {
69
70
async notifyUploadFile ( { dispatch } , payload ) { dispatch ( 'notifyCreateFile' , payload ) } ,
70
71
71
72
// New notifications
72
- async notifyRootUpdate ( { commit } , payload : FileChangeSocketResponse ) {
73
+ async notifyRootUpdate ( { commit } , payload : FileChange ) {
73
74
const root = payload . item . root
74
75
75
76
commit ( 'setResetRoot' , root )
76
77
77
78
SocketActions . serverFilesGetDirectory ( root )
78
79
} ,
79
80
80
- async notifyModifyFile ( { dispatch } , payload : FileChangeSocketResponse ) { dispatch ( 'notifyCreateFile' , payload ) } ,
81
+ async notifyModifyFile ( { dispatch } , payload : FileChange ) { dispatch ( 'notifyCreateFile' , payload ) } ,
81
82
82
- async notifyCreateFile ( { commit, dispatch, rootState } , payload : FileChangeSocketResponse ) {
83
+ async notifyCreateFile ( { commit, dispatch, rootState } , payload : FileChange ) {
83
84
const paths = getFilePaths ( payload . item . path , payload . item . root )
84
85
85
86
if ( ! paths . filtered ) {
@@ -101,30 +102,30 @@ export const actions: ActionTree<FilesState, RootState> = {
101
102
// For gcode files, get the metadata and the meta update will take care of the rest.
102
103
SocketActions . serverFilesMetadata ( paths . pathFilename )
103
104
} else {
104
- const file = itemAsKlipperFile ( payload . item , paths )
105
+ const file = itemAsMoonrakerFile ( payload . item , paths )
105
106
106
107
commit ( 'setFileUpdate' , { paths, file } )
107
108
}
108
109
}
109
110
} ,
110
111
111
- async notifyCreateDir ( { commit } , payload : FileChangeSocketResponse ) {
112
+ async notifyCreateDir ( { commit } , payload : FileChange ) {
112
113
const paths = getFilePaths ( payload . item . path , payload . item . root )
113
114
114
115
if ( ! paths . filtered ) {
115
- const dir = itemAsKlipperDir ( payload . item , paths )
116
+ const dir = itemAsMoonrakerDir ( payload . item , paths )
116
117
117
118
commit ( 'setDirUpdate' , { paths, dir } )
118
119
}
119
120
} ,
120
121
121
- async notifyMoveFile ( { commit } , payload : FileChangeSocketResponse ) {
122
+ async notifyMoveFile ( { commit } , payload : FileChange ) {
122
123
const { item, source_item } = payload
123
124
124
125
const paths = getFilePaths ( item . path , item . root )
125
126
126
127
if ( ! paths . filtered ) {
127
- const file = itemAsKlipperFile ( payload . item , paths )
128
+ const file = itemAsMoonrakerFile ( payload . item , paths )
128
129
129
130
commit ( 'setFileUpdate' , { paths, file } )
130
131
}
@@ -138,13 +139,13 @@ export const actions: ActionTree<FilesState, RootState> = {
138
139
}
139
140
} ,
140
141
141
- async notifyMoveDir ( { commit } , payload : FileChangeSocketResponse ) {
142
+ async notifyMoveDir ( { commit } , payload : FileChange ) {
142
143
const { item, source_item } = payload
143
144
144
145
const paths = getFilePaths ( item . path , item . root )
145
146
146
147
if ( ! paths . filtered ) {
147
- const dir = itemAsKlipperDir ( payload . item , paths )
148
+ const dir = itemAsMoonrakerDir ( payload . item , paths )
148
149
149
150
commit ( 'setDirUpdate' , { paths, dir } )
150
151
}
@@ -160,15 +161,15 @@ export const actions: ActionTree<FilesState, RootState> = {
160
161
}
161
162
} ,
162
163
163
- async notifyDeleteFile ( { commit } , payload : FileChangeSocketResponse ) {
164
+ async notifyDeleteFile ( { commit } , payload : FileChange ) {
164
165
const paths = getFilePaths ( payload . item . path , payload . item . root )
165
166
166
167
if ( ! paths . filtered ) {
167
168
commit ( 'setFileDelete' , paths )
168
169
}
169
170
} ,
170
171
171
- async notifyDeleteDir ( { commit } , payload : FileChangeSocketResponse ) {
172
+ async notifyDeleteDir ( { commit } , payload : FileChange ) {
172
173
const paths = getFilePaths ( payload . item . path , payload . item . root )
173
174
174
175
if ( ! paths . filtered ) {
0 commit comments