Commit 9f772107 authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Add JS properties to assist with web-access to filebase

file_area.web_vpath_prefix
file-metadata-object (return value of FileBase.get()).vpath
parent 3e5326e0
Pipeline #2581 passed with stage
in 12 minutes and 19 seconds
......@@ -563,6 +563,16 @@ char* getfilepath(scfg_t* cfg, file_t* f, char* path)
return path;
}
char* getfilevpath(scfg_t* cfg, file_t* f, char* path)
{
const char* name = f->name == NULL ? f->file_idx.name : f->name;
if(f->dir >= cfg->total_dirs)
return "";
safe_snprintf(path, MAX_PATH, "%s/%s"
,cfg->lib[cfg->dir[f->dir]->lib]->sname, cfg->dir[f->dir]->code_suffix, name);
return path;
}
off_t getfilesize(scfg_t* cfg, file_t* f)
{
char fpath[MAX_PATH + 1];
......
......@@ -49,6 +49,7 @@ DLLEXPORT str_list_t loadfilenames(smb_t*, const char* filespec, time_t t, enum
DLLEXPORT void sortfilenames(str_list_t, size_t count, enum file_sort);
DLLEXPORT bool updatefile(scfg_t*, file_t*);
DLLEXPORT char* getfilepath(scfg_t*, file_t*, char* path);
DLLEXPORT char* getfilevpath(scfg_t*, file_t*, char* path);
DLLEXPORT off_t getfilesize(scfg_t*, file_t*);
DLLEXPORT time_t getfiletime(scfg_t*, file_t*);
DLLEXPORT ulong gettimetodl(scfg_t*, file_t*, uint rate_cps);
......
......@@ -27,6 +27,7 @@
static char* file_area_prop_desc[] = {
"minimum amount of available disk space (in kilobytes) required for user uploads to be allowed"
,"file area settings (bitfield) - see <tt>FM_*</tt> in <tt>sbbsdefs.js</tt> for details"
,"web file virtual path prefix <i>(introduced in v3.19c)</i>"
,NULL
};
......@@ -230,6 +231,17 @@ JSBool js_file_area_resolve(JSContext* cx, JSObject* areaobj, jsid id)
return(JS_TRUE);
}
if(name==NULL || strcmp(name, "web_vpath_prefix")==0) {
if(name)
free(name);
if((js_str=JS_NewStringCopyZ(cx, p->cfg->web_file_prefix))==NULL)
return JS_FALSE;
val=STRING_TO_JSVAL(js_str);
JS_DefineProperty(cx, areaobj, "web_vpath_prefix", val, NULL, NULL, JSPROP_ENUMERATE);
if(name)
return(JS_TRUE);
}
#ifdef BUILD_JSDOCS
js_CreateArrayOfStrings(cx, areaobj, "_property_desc_list", file_area_prop_desc, JSPROP_READONLY);
#endif
......
......@@ -167,6 +167,7 @@ js_dump_file(JSContext *cx, uintN argc, jsval *arglist)
static bool
set_file_properties(JSContext *cx, JSObject* obj, file_t* f, enum file_detail detail)
{
char path[MAX_PATH + 1];
jsval val;
JSString* js_str;
const uintN flags = JSPROP_ENUMERATE;
......@@ -181,6 +182,10 @@ set_file_properties(JSContext *cx, JSObject* obj, file_t* f, enum file_detail de
|| !JS_DefineProperty(cx, obj, "name", STRING_TO_JSVAL(js_str), NULL, NULL, flags))
return false;
if((js_str = JS_NewStringCopyZ(cx, getfilevpath(scfg, f, path))) == NULL
|| !JS_DefineProperty(cx, obj, "vpath", STRING_TO_JSVAL(js_str), NULL, NULL, flags | JSPROP_READONLY))
return false;
if(((f->from != NULL && *f->from != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->from)) == NULL
|| !JS_DefineProperty(cx, obj, "from", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
......@@ -1596,6 +1601,7 @@ static jsSyncMethodSpec js_filebase_functions[] = {
"The file-meta-object may contain the following properties (depending on <i>detail</i> value):<br>"
"<table>"
"<tr><td align=top><tt>name</tt><td>Filename <i>(required)</i>"
"<tr><td align=top><tt>vpath</tt><td>Virtual path to file <i>READ ONLY</i>"
"<tr><td align=top><tt>desc</tt><td>Description (summary, 58 chars or less)"
"<tr><td align=top><tt>extdesc</tt><td>Extended description (multi-line description, e.g. DIZ)"
"<tr><td align=top><tt>author</tt><td>File author name (e.g. from SAUCE record)"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment