File tree 2 files changed +56
-0
lines changed 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,12 @@ const readOrDefault = filename => fs.existsSync(filename)
41
41
? fs . readJsonSync ( filename )
42
42
: [ ] ;
43
43
44
+ /**
45
+ * @typedef InstallPackageOptions
46
+ * @param {boolean } system
47
+ * @param {object } [auth]
48
+ */
49
+
44
50
/**
45
51
* OS.js Package Management
46
52
*/
@@ -133,6 +139,36 @@ class Packages {
133
139
} , 500 ) ;
134
140
}
135
141
142
+ /**
143
+ * Installs a package from given url
144
+ * @param {string } url
145
+ * @param {InstallPackageOptions } options
146
+ */
147
+ async installPackage ( url , options ) {
148
+ throw new Error ( 'Not implemented yet' ) ;
149
+ }
150
+
151
+ /**
152
+ * Reads package manifests
153
+ * @return {Package[] } List of packages
154
+ */
155
+ async readPackageManifests ( user ) {
156
+ const { realpath} = this . core . make ( 'osjs/vfs' ) ;
157
+ const { manifestFile} = this . options ;
158
+ const homePath = await realpath ( 'home:/.packages/metadata.json' , user ) ;
159
+
160
+ const systemManifest = await readOrDefault ( manifestFile ) ;
161
+ const userManifest = await readOrDefault ( homePath ) ;
162
+
163
+ return [
164
+ ...systemManifest ,
165
+ ...userManifest . map ( pkg => Object . assign ( { } , pkg , {
166
+ _user : true ,
167
+ server : null
168
+ } ) )
169
+ ] ;
170
+ }
171
+
136
172
/**
137
173
* Loads package data
138
174
* @param {string } filename Filename
Original file line number Diff line number Diff line change @@ -55,15 +55,35 @@ class PackageServiceProvider extends ServiceProvider {
55
55
} ) ;
56
56
}
57
57
58
+ depends ( ) {
59
+ return [
60
+ 'osjs/express'
61
+ ] ;
62
+ }
63
+
58
64
provides ( ) {
59
65
return [
60
66
'osjs/packages'
61
67
] ;
62
68
}
63
69
64
70
init ( ) {
71
+ const { routeAuthenticated} = this . core . make ( 'osjs/express' ) ;
72
+
65
73
this . core . singleton ( 'osjs/packages' , ( ) => this . packages ) ;
66
74
75
+ routeAuthenticated ( 'GET' , '/api/packages/manifest' , ( req , res ) => {
76
+ this . packages . readPackageManifests ( req . session . user )
77
+ . then ( json => res . json ( json ) )
78
+ . catch ( error => res . status ( 400 ) . json ( { error} ) ) ;
79
+ } ) ;
80
+
81
+ routeAuthenticated ( 'POST' , '/api/packages/install' , ( req , res ) => {
82
+ this . packages . installPackage ( req . body . url , req . body . options )
83
+ . then ( ( ) => res . json ( { success : true } ) )
84
+ . catch ( error => res . status ( 400 ) . json ( { error} ) ) ;
85
+ } ) ;
86
+
67
87
return this . packages . init ( ) ;
68
88
}
69
89
You can’t perform that action at this time.
0 commit comments