2001-11-03 09:17:41 +00:00
|
|
|
/**
|
2002-06-26 16:57:38 +00:00
|
|
|
* function checks if file fits to the minimal needs
|
|
|
|
* @param Obj Object containing the properties needed for creating a new file
|
|
|
|
* @param Obj User-Object creating this file
|
2001-12-10 22:55:34 +00:00
|
|
|
* @return Obj Object containing two properties:
|
|
|
|
* - error (boolean): true if error happened, false if everything went fine
|
|
|
|
* - message (String): containing a message to user
|
2001-11-03 09:17:41 +00:00
|
|
|
*/
|
2003-08-02 11:20:24 +00:00
|
|
|
function evalFile(param, creator) {
|
2001-12-10 22:55:34 +00:00
|
|
|
if (param.uploadError) {
|
2001-11-03 09:17:41 +00:00
|
|
|
// looks like the file uploaded has exceeded uploadLimit ...
|
2003-08-02 11:20:24 +00:00
|
|
|
throw new Exception("fileFileTooBig");
|
|
|
|
}
|
|
|
|
if (!param.rawfile || param.rawfile.contentLength == 0) {
|
|
|
|
// looks like nothing was uploaded ...
|
|
|
|
throw new Exception("fileNoUpload");
|
2001-11-03 09:17:41 +00:00
|
|
|
}
|
2003-08-02 11:20:24 +00:00
|
|
|
var newFile = new file(creator);
|
|
|
|
// if no alias given try to determine it
|
|
|
|
if (!param.alias)
|
|
|
|
newFile.alias = buildAliasFromFile(param.rawfile, this);
|
|
|
|
else {
|
|
|
|
if (!param.alias.isFileName())
|
|
|
|
throw new Exception("noSpecialChars");
|
|
|
|
newFile.alias = buildAlias(param.alias, this);
|
|
|
|
}
|
|
|
|
// store properties necessary for file-creation
|
|
|
|
newFile.alttext = param.alttext;
|
|
|
|
newFile.name = newFile.alias;
|
|
|
|
newFile.filesize = param.rawfile.contentLength;
|
|
|
|
newFile.mimetype = param.rawfile.contentType;
|
|
|
|
newFile.description = param.description;
|
2003-11-23 18:35:42 +00:00
|
|
|
var dir = this._parent.getStaticPath("files").toString();
|
|
|
|
newFile.name = param.rawfile.writeToFile(dir, newFile.name);
|
2003-08-02 11:20:24 +00:00
|
|
|
if (!newFile.name)
|
|
|
|
throw new Exception("fileSave");
|
|
|
|
// the file is on disk, so we add the file-object
|
|
|
|
if (!this.add(newFile))
|
|
|
|
throw new Exception("fileCreate", newFile.alias);
|
2003-10-06 16:28:03 +00:00
|
|
|
// send e-mail notification
|
2003-11-23 18:35:42 +00:00
|
|
|
if (newFile.site.isNotificationEnabled())
|
2003-10-08 16:17:22 +00:00
|
|
|
newFile.site.sendNotification("upload", newFile);
|
2003-08-02 11:20:24 +00:00
|
|
|
return new Message("fileCreate", newFile.alias);
|
2001-11-03 09:17:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2002-06-26 16:57:38 +00:00
|
|
|
* delete a file
|
|
|
|
* @param Obj file-object to delete
|
2001-12-10 22:55:34 +00:00
|
|
|
* @return String Message indicating success or failure
|
2001-11-03 09:17:41 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-02 11:20:24 +00:00
|
|
|
function deleteFile(fileObj) {
|
2002-06-26 16:57:38 +00:00
|
|
|
// first remove the file from disk
|
2003-11-23 18:35:42 +00:00
|
|
|
var f = FileLib.get(this._parent.getStaticPath("files"), fileObj.name);
|
2002-02-06 18:21:04 +00:00
|
|
|
f.remove();
|
2003-08-02 11:20:24 +00:00
|
|
|
if (!this.remove(fileObj))
|
|
|
|
throw new Exception("fileDelete");
|
|
|
|
return new Message("fileDelete");
|
2002-03-27 11:18:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2002-06-26 16:57:38 +00:00
|
|
|
* function deletes all files
|
2002-03-27 11:18:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
function deleteAll() {
|
2003-08-02 11:20:24 +00:00
|
|
|
for (var i=this.size();i>0;i--)
|
|
|
|
this.deleteFile(this.get(i-1));
|
2002-03-27 11:18:36 +00:00
|
|
|
return true;
|
2001-11-03 09:17:41 +00:00
|
|
|
}
|