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 @@ -54,15 +54,35 @@ class PackageServiceProvider extends ServiceProvider {
54
54
} ) ;
55
55
}
56
56
57
+ depends ( ) {
58
+ return [
59
+ 'osjs/express'
60
+ ] ;
61
+ }
62
+
57
63
provides ( ) {
58
64
return [
59
65
'osjs/packages'
60
66
] ;
61
67
}
62
68
63
69
init ( ) {
70
+ const { routeAuthenticated} = this . core . make ( 'osjs/express' ) ;
71
+
64
72
this . core . singleton ( 'osjs/packages' , ( ) => this . packages ) ;
65
73
74
+ routeAuthenticated ( 'GET' , '/api/packages/manifest' , ( req , res ) => {
75
+ this . packages . readPackageManifests ( req . session . user )
76
+ . then ( json => res . json ( json ) )
77
+ . catch ( error => res . status ( 400 ) . json ( { error} ) ) ;
78
+ } ) ;
79
+
80
+ routeAuthenticated ( 'POST' , '/api/packages/install' , ( req , res ) => {
81
+ this . packages . installPackage ( req . body . url , req . body . options )
82
+ . then ( ( ) => res . json ( { success : true } ) )
83
+ . catch ( error => res . status ( 400 ) . json ( { error} ) ) ;
84
+ } ) ;
85
+
66
86
return this . packages . init ( ) ;
67
87
}
68
88
You can’t perform that action at this time.
0 commit comments