Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
css
js
lib
test
README.md
admin.html
admins.js
server.js
settings.js
settings.json
users.js

README.md

Intro

Connect server that handles file upload and download requests, as well as basic searching by mimetype.

File data is stored in a CouchDB database and files are stored on the system.

Directory structure goes 4 levels down using the md5 sum in 2 character chunks as directory names and file names are the md5 sums. For example:

MD5- be121740bf988b2225a313fa1f107ca1 Path- be/12/17/40/be121740bf988b2225a313fa1f107ca1

Source Guide

The source is laid out pretty logically, but here is a little guide to get you familiar with it... after all, this project could use all the help it can get.

  • server.js- connect server, drives everything
  • settings.js- settings for the server, loaded from settings.json
  • settings.json- settings file for the server
    • doc_root- document root for static file access (such as for admin.html)
    • port- port that the server runs on
    • cpu_timeout- used in admin console; affects delay in CPU monitor update
    • media_root- root for uploaded file directory tree
  • admin.js- simple JSON for doing admin authentication while in testing
  • admin.html- administration console
  • users.js- simple JSON for doing authentication while in testing
  • lib- this is where everything useful goes
    • dbaccess.js- all database access must go through this module
    • routes.js- defines the routes used in connect.router in the server
    • utils.js- extra functions that are globally useful
  • lib/routes- definitions of the different route functions
    • admin.js- loads admin console, may be moved to / in the future
    • check.js- allows client to check the server to see if a file exists
    • download.js- like the name implies, handles download requests
    • meta.js- allows client to get a list of files by mime-type
    • register.js- registers a client with the database
    • upload.js- handles uploads

Usage Guide

Clients interract with the server through resources. Each client must authenticate with the server through a simple username and password. Data is not encrypted in any way.

Get requests:

  • /admin
    • loads admin console
    • requires admin access
  • /file
    • takes an array of objects each with an md5 hash
    • returns a gzipped tarball with files (named by md5 hash)
  • /meta/category/type
    • category/type represents a mimetype
    • gets an array of filestat objects based on the category and type passed
    • value is optional; will return all objects with the same category
    • returned value is JSON
  • /register
    • registers a new client with the database
    • takes three parameters:
      • user- username of the new client
      • pass- password of the new client
      • data- any extra data that should be stored
    • data is pulled from the query portion of the url

Post requests:

  • /
    • same as /file
    • very likely to change in future releases
  • /check
    • takes an array of filestat objects
    • must have: tmd5 and qmd5
    • returns- filestats of each matched object, adding an exists property
  • /file
    • streams file uploads using formidable
    • takes two parameters in fields:
      • statsHeader
        • an array detailing the structure of the stats object
        • e.g. ['path', 'qsum'] => { 'path': '', 'qsum': '' }
      • stats- has these properties
        • md5- if present, the server will check it against the one it generates
        • mtime- necessary; used to generate qmd5 on server
        • path- necessary; used to generate mimeType & qmd5
        • qmd5- necessary; must match qmd5 generated by the server
        • size- necessary; used to generate qmd5 on server
        • any other properties will be stored in the database
      • returns an array of the updated filestat objects with any errors
  • register
    • registers a new client with the database
    • takes three parameters:
      • user- username of the new client
      • pass- password of the new client
      • data- any extra data that should be stored
    • data is pulled from the body of the request