@@ -196,6 +196,63 @@ function userApikeyDefault($args)
196
196
}
197
197
}
198
198
199
+ /**
200
+ * Create a link bitstream. POST is required.
201
+ * @path /system/createlink
202
+ * @http POST
203
+ * @param useSession (Optional) Authenticate using the current Midas session
204
+ * @param token (Optional) Authentication token
205
+ * @param folderid
206
+ The id of the folder in which to create a new item that will
207
+ contain the link. The new item will have the same name as
208
+ <b>url</b> unless <b>itemname</b> is supplied.
209
+ * @param url The URL of the link you will create, will be used as the name
210
+ of the bitstream and of the item (unless <b>itemname</b> is
211
+ supplied).
212
+ * @param itemname (Optional)
213
+ The name of the newly created item, if not supplied, the item will
214
+ have the same name as <b>url</b>.
215
+ * @return The item information of the item created.
216
+ */
217
+ function linkCreate ($ args )
218
+ {
219
+ $ request = Zend_Controller_Front::getInstance ()->getRequest ();
220
+ if (!$ request ->isPost ())
221
+ {
222
+ throw new Exception ('POST method required ' , MIDAS_HTTP_ERROR );
223
+ }
224
+ $ apihelperComponent = MidasLoader::loadComponent ('Apihelper ' );
225
+ $ apihelperComponent ->validateParams ($ args , array ('folderid ' , 'url ' ));
226
+ $ apihelperComponent ->requirePolicyScopes (array (MIDAS_API_PERMISSION_SCOPE_WRITE_DATA ));
227
+ $ userDao = $ apihelperComponent ->getUser ($ args );
228
+ if (!$ userDao )
229
+ {
230
+ throw new Exception ('Anonymous users may not create a link ' , MIDAS_INVALID_POLICY );
231
+ }
232
+ $ folderModel = MidasLoader::loadModel ('Folder ' );
233
+ $ folder = $ folderModel ->load ($ args ['folderid ' ]);
234
+ if ($ folder === false )
235
+ {
236
+ throw new Exception ('Folder corresponding to folderid does not exist ' , MIDAS_INVALID_PARAMETER );
237
+ }
238
+ if (!$ folderModel ->policyCheck ($ folder , $ userDao , MIDAS_POLICY_WRITE ))
239
+ {
240
+ throw new Exception ('Invalid policy or folderid ' , MIDAS_INVALID_POLICY );
241
+ }
242
+ if (!filter_var ($ args ['url ' ], FILTER_VALIDATE_URL ))
243
+ {
244
+ throw new Exception ('Invalid URL ' , MIDAS_INVALID_PARAMETER );
245
+ }
246
+ $ itemname = isset ($ args ['itemname ' ]) ? $ args ['itemname ' ] : $ args ['url ' ];
247
+ $ uploadComponent = MidasLoader::loadComponent ('Upload ' );
248
+ $ item = $ uploadComponent ->createLinkItem ($ userDao , $ itemname , $ args ['url ' ], $ folder );
249
+ if (!$ item )
250
+ {
251
+ throw new Exception ('Link creation failed ' , MIDAS_INTERNAL_ERROR );
252
+ }
253
+ return $ item ->toArray ();
254
+ }
255
+
199
256
/**
200
257
* Generate a unique upload token. Either <b>itemid</b> or <b>folderid</b> is required,
201
258
but both are not allowed.
0 commit comments