| | @@ -248,15 +248,30 @@ |
| 248 | 248 | contentFormat = json_artifact_include_content_flag() ? -1 : 0; |
| 249 | 249 | } |
| 250 | 250 | return json_get_wiki_page_by_rid(rid, contentFormat); |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | + |
| 254 | +/* |
| 255 | +** Internal helper for routines which add a "status" flag to file |
| 256 | +** artifact data. isNew and isDel should be the "is this object new?" |
| 257 | +** and "is this object removed?" flags of the underlying query. This |
| 258 | +** function returns a static string from the set (added, removed, |
| 259 | +** modified), depending on the combination of the two args. |
| 260 | +** |
| 261 | +** Reminder to self: (mlink.pid==0) AS isNew, (mlink.fid==0) AS isDel |
| 262 | +*/ |
| 263 | +char const * json_artifact_status_to_string( char isNew, char isDel ){ |
| 264 | + return isNew |
| 265 | + ? "added" |
| 266 | + : (isDel |
| 267 | + ? "removed" |
| 268 | + : "modified"); |
| 269 | +} |
| 253 | 270 | |
| 254 | 271 | cson_value * json_artifact_file(int rid){ |
| 255 | 272 | cson_object * pay = NULL; |
| 256 | | - const char *zMime; |
| 257 | | - Blob content = empty_blob; |
| 258 | 273 | Stmt q = empty_Stmt; |
| 259 | 274 | cson_array * checkin_arr = NULL; |
| 260 | 275 | |
| 261 | 276 | if( ! g.perm.Read ){ |
| 262 | 277 | json_set_err(FSL_JSON_E_DENIED, |
| | @@ -264,35 +279,39 @@ |
| 264 | 279 | return NULL; |
| 265 | 280 | } |
| 266 | 281 | |
| 267 | 282 | pay = cson_new_object(); |
| 268 | 283 | |
| 269 | | - content_get(rid, &content); |
| 270 | | - cson_object_set(pay, "contentLength", |
| 271 | | - json_new_int( blob_size(&content) ) |
| 272 | | - /* achtung: overflow potential on 32-bit builds! */); |
| 273 | | - zMime = mimetype_from_content(&content); |
| 274 | | - |
| 275 | | - cson_object_set(pay, "contentType", |
| 276 | | - json_new_string(zMime ? zMime : "text/plain")); |
| 277 | | - if( json_artifact_include_content_flag() && !zMime ){ |
| 284 | + if( json_artifact_include_content_flag() ){ |
| 285 | + Blob content = empty_blob; |
| 286 | + const char *zMime; |
| 287 | + content_get(rid, &content); |
| 288 | + zMime = mimetype_from_content(&content); |
| 289 | + cson_object_set(pay, "contentType", |
| 290 | + json_new_string(zMime ? zMime : "text/plain")); |
| 291 | + cson_object_set(pay, "size", json_new_int( blob_size(&content)) ); |
| 292 | + if(!zMime){ |
| 278 | 293 | cson_object_set(pay, "content", |
| 279 | 294 | cson_value_new_string(blob_str(&content), |
| 280 | 295 | (unsigned int)blob_size(&content))); |
| 296 | + } |
| 297 | + blob_reset(&content); |
| 281 | 298 | } |
| 282 | | - blob_reset(&content); |
| 283 | 299 | |
| 284 | 300 | db_prepare(&q, |
| 285 | 301 | "SELECT filename.name AS name, " |
| 286 | | - " cast(strftime('%%s',event.mtime) as int) AS timestamp," |
| 287 | | - " coalesce(event.ecomment,event.comment) as comment," |
| 288 | | - " coalesce(event.euser,event.user) as user," |
| 289 | | - " b.uuid as uuid, " |
| 302 | + " (mlink.pid==0) AS isNew," |
| 303 | + " (mlink.fid==0) AS isDel," |
| 304 | + " cast(strftime('%%s',event.mtime) as int) AS timestamp," |
| 305 | + " coalesce(event.ecomment,event.comment) as comment," |
| 306 | + " coalesce(event.euser,event.user) as user," |
| 307 | + " a.size AS size," |
| 308 | + " b.uuid as uuid, " |
| 290 | 309 | #if 0 |
| 291 | | - " mlink.mperm as mperm," |
| 310 | + " mlink.mperm as mperm," |
| 292 | 311 | #endif |
| 293 | | - " coalesce((SELECT value FROM tagxref" |
| 312 | + " coalesce((SELECT value FROM tagxref" |
| 294 | 313 | " WHERE tagid=%d AND tagtype>0 AND " |
| 295 | 314 | " rid=mlink.mid),'trunk') as branch" |
| 296 | 315 | " FROM mlink, filename, event, blob a, blob b" |
| 297 | 316 | " WHERE filename.fnid=mlink.fnid" |
| 298 | 317 | " AND event.objid=mlink.mid" |
| | @@ -305,11 +324,20 @@ |
| 305 | 324 | /* TODO: add a "state" flag for the file in each checkin, |
| 306 | 325 | e.g. "modified", "new", "deleted". |
| 307 | 326 | */ |
| 308 | 327 | checkin_arr = cson_new_array(); |
| 309 | 328 | cson_object_set(pay, "checkins", cson_array_value(checkin_arr)); |
| 310 | | - json_stmt_to_array_of_obj( &q, checkin_arr ); |
| 329 | + while( (SQLITE_ROW==db_step(&q) ) ){ |
| 330 | + cson_object * row = cson_value_get_object(cson_sqlite3_row_to_object(q.pStmt)); |
| 331 | + char const isNew = cson_value_get_bool(cson_object_get(row,"isNew")); |
| 332 | + char const isDel = cson_value_get_bool(cson_object_get(row,"isDel")); |
| 333 | + cson_object_set(row, "isNew", NULL); |
| 334 | + cson_object_set(row, "isDel", NULL); |
| 335 | + cson_object_set(row, "status", |
| 336 | + json_new_string(json_artifact_status_to_string(isNew, isDel))); |
| 337 | + cson_array_append( checkin_arr, cson_object_value(row) ); |
| 338 | + } |
| 311 | 339 | db_finalize(&q); |
| 312 | 340 | return cson_object_value(pay); |
| 313 | 341 | } |
| 314 | 342 | |
| 315 | 343 | /* |
| 316 | 344 | |