FileMgr.evalFile (param, creator)
function checks if file fits to the minimal needs

  • Parameter Obj:
    Object containing the properties needed for creating a new File
  • Parameter Obj:
    User-Object creating this file
  • Returns
    Obj Object containing two properties: - error (boolean): true if error happened, false if everything went fine - message (String): containing a message to user
Sourcecode in FileMgr/objectFunctions.js:
1:   function evalFile(param, creator) {
2:      if (param.uploadError) {
3:         // looks like the file uploaded has exceeded uploadLimit ...
4:         throw new Exception("fileFileTooBig");
5:      }
6:      if (!param.rawfile || param.rawfile.contentLength == 0) {
7:         // looks like nothing was uploaded ...
8:         throw new Exception("fileNoUpload");
9:      }
10:     var filesize = Math.round(param.rawfile.contentLength / 1024);
11:     if (this._parent.getDiskUsage() + filesize > this._parent.getDiskQuota()) {
12:        // disk quota has already been exceeded
13:        throw new Exception("siteQuotaExceeded");
14:     }
15:     var newFile = new File(creator);
16:     // if no alias given try to determine it
17:     if (!param.alias)
18:        newFile.alias = buildAliasFromFile(param.rawfile, this);
19:     else {
20:        if (!param.alias.isFileName())
21:           throw new Exception("noSpecialChars");
22:        newFile.alias = buildAlias(param.alias, this);
23:     }
24:     // store properties necessary for file-creation
25:     newFile.alttext = param.alttext;
26:     newFile.name = newFile.alias;
27:     newFile.filesize = param.rawfile.contentLength;
28:     newFile.mimetype = param.rawfile.contentType;
29:     newFile.description = param.description;
30:     var dir = this._parent.getStaticPath("files");
31:     newFile.name = param.rawfile.writeToFile(dir, newFile.name);
32:     if (!newFile.name)
33:        throw new Exception("fileSave");
34:     // the file is on disk, so we add the file-object
35:     if (!this.add(newFile))
36:        throw new Exception("fileCreate", newFile.alias);
37:     // send e-mail notification
38:     if (newFile.site.isNotificationEnabled())
39:        newFile.site.sendNotification("upload", newFile);
40:     newFile.site.diskusage += newFile.filesize;
41:     return new Message("fileCreate", newFile.alias, newFile);
42:  }