antville/code/FileMgr/objectFunctions.js

67 lines
2.2 KiB
JavaScript
Raw Normal View History

2001-11-03 09:17:41 +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
* @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
*/
function evalFile(param, creator) {
if (param.uploadError) {
2001-11-03 09:17:41 +00:00
// looks like the file uploaded has exceeded uploadLimit ...
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
}
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;
var saveTo = getProperty("filePath") + this._parent.alias + "/";
newFile.name = param.rawfile.writeToFile(saveTo, newFile.name);
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);
return new Message("fileCreate", newFile.alias);
2001-11-03 09:17:41 +00:00
}
/**
* delete a file
* @param Obj file-object to delete
* @return String Message indicating success or failure
2001-11-03 09:17:41 +00:00
*/
function deleteFile(fileObj) {
// first remove the file from disk
var f = FileLib.get(getProperty("filePath") + fileObj.site.alias, fileObj.name);
f.remove();
if (!this.remove(fileObj))
throw new Exception("fileDelete");
return new Message("fileDelete");
2002-03-27 11:18:36 +00:00
}
/**
* function deletes all files
2002-03-27 11:18:36 +00:00
*/
function deleteAll() {
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
}