Revision as of 04:57, 22 August 2019 by Antonizoon (talk | contribs) (How asagi does stuff)


Fuuka Imageboard Archival Standard (Fuuka)

Note: Not to be confused with the FoolFuuka frontend, which uses the Asagi scraper.

Asagi Imageboard Archival Standard (Asagi)

The Asagi Imageboard Archival Standard was developed by eksopl of Easymodo and the Foolz team under the direction of woxxy. It was developed to run the Foolz archiver, and has been the engine for the majority of archivers since the collapse of

Three versions can be identified:

  • Mark I (2009) - Produced for Maybe in use by Nyafuu, was in use by Loveisover.
  • Mark II (2015) - Produced for Used by Fireden and
  • Mark III (2019) - The final reference standard codified by the Bibliotheca Anonoma, in preparation for the development of new drop-in replacements.

Reference Implementation

New Implementation

Proposed, still needs to be constructed.

Compilation and Usage


Also check FoolFuuka/Install/Ubuntu16#Install_and_compile_Asagi_from_source.


Also check FoolFuuka/Install/Ubuntu16

How asagi does stuff


Seperate thread for (thumbs, media, topic-fetch, topic-insert, post-delete) per board ln. 95: public void initDumper(BoardSettings boardSettings) {

How asagi decides to update a thread:


When asagi does a thread update:

in :, ln. 88: public Topic getThread(int threadNum, String lastMod) throws ContentGetException, ContentParseException, CfBicClearParseException {

Loads thread JSON Decodes JSON For each post in the decoded thread JSON: Check if resto value is zero, and if so create a new thread from that post, updating lastmodified time to the time from fetching the JSON. t = this.makeThreadFromJson(pj); If resto is zero: Add the post to the current thread. t.addPost(this.makePostFromJson(pj)); (What if two posts were resto==0? We’d break!)

What does asagi do with a post in a thread?

Relevant files: > >

The entire thread is processed at once.

For OP:

In, ln. 217: private Topic makeThreadFromJson(PostJson pj) throws ContentParseException {

Ensure post number is zero. Create a new Topic() object (ln222): Topic t = new Topic(pj.getNo(), pj.getOmittedPosts(), pj.getOmittedImages());

Add the supplied OP to the thread as any other would be (ln. 224): t.addPost(this.makePostFromJson(pj));

Return the Thread() object. DONE

For reply:

In, (ln. 157:) private Post makePostFromJson(PostJson pj) throws ContentParseException {

Ensure post number is valid. Ensure time is valid. Create new Post() object.

If the JSON gave a filename not equal to null: Generate filename from JSON values. p.setMediaFilename(pj.getFilename() + pj.getExt());

Generate original filename from JSON values. p.setMediaOrig(pj.getTim() + pj.getExt());

Generate preview original filename from JSON values. p.setPreviewOrig(pj.getTim() + "s.jpg");

Find the post’s capcode, and if not null: Manager -> “G” Anything else: first character as uppercase.

Find the post hash (tripcode?) If the post hash is “Developer”, set the post hash value to “Dev”

If the post country is not null: Convert values “XX” or “A1” if they are used to null.

Pass through values from JSON (ln. 188 -> 212), doing the following conversions:

Thread num to the current thread number: .setThreadNum(pj.getResto() == 0 ? pj.getNo() : pj.getResto());

OP status (ln. 197): p.setOp(pj.getResto() == 0);

Sanitized title? (ln. 198): p.setTitle(this.cleanSimple(pj.getSub()));

See (ln.83): public String doClean(String text)

Sanitized name (ln. 200): p.setName(this.cleanSimple(pj.getName()));

Date converted from NYC_TIMEZONE (ln. 202): p.setDate(DateUtils.adjustTimestampEpoch(pj.getTime(), DateUtils.NYC_TIMEZONE));

Sanitized? EXIF data (ln. 212): p.setExif(this.cleanSimple(this.parseMeta(pj.getCom(), pj.getUniqueIps(), pj.getSince4pass(), pj.getTrollCountry()))); Return the Post() object.

How asagi handles an image in a thread?

Files of note: > - Saving image files ln.201: public void insertMedia(MediaPost h, Board source, boolean isPreview) throws ContentGetException, ContentStoreException, CfBicClearParseException {

How asagi deals with post deletions?

Relevant files: > > >

SQL That handles post deletion logic: (ln. 94): “this.updateDeletedQuery = String.format("UPDATE \"%s\" SET deleted = ?, timestamp_expired = ? WHERE num = ? AND subnum = ?", this.table);

This is prepared into statement, (ln.62): updateDeletedStmt = conn.prepareStatement(updateDeletedQuery);

Function that actually writes deleted flag to a post: (ln. 267): public synchronized void markDeleted(DeletedPost post) throws ContentStoreException, DBConnectionException {

Class TopicFetcher has function run() which calls findDeleted() See (ln. 268): protected class TopicFetcher implements Runnable {

And (ln. 380): findDeleted(oldTopic, topic, true);

Function findDeleted() checks Posts in a Topic to check if they have been removed in (ln. 103): protected boolean findDeleted(Topic oldTopic, Topic newTopic, boolean markDeleted) {

Function markDeleted() in calls function markDeleted() from (ln. 185): public void markDeleted(DeletedPost post) throws ContentStoreException { (ln. 267): public synchronized void markDeleted(DeletedPost post) throws ContentStoreException, DBConnectionException {

How Asagi interacts with the database?

Relevant files: > >

Inserting a thread:, ln.196: public synchronized void insert(Topic topic) throws ContentStoreException, DBConnectionException { Each post in the current Topic object is fed through the insert statement sequentially.

How each value is processed between 4ch and the DB

4chan API JSON broken down to post level ( ln.97), then: ?PostJson are created/populated from the thread JSON data, with values keeping the names from the API? (, ln.4) (DISREGARD CAPITALIZATION, GOOG DOCS FUCKS WITH IT. EVERYTHING IS LOWERCASE) DB column names referenced here: ( ln.79):


4ch → (Asagi) → DB


Presumably always NULL? PROVEME Does not appear to ever be initialized to a value in the java source code as far as i can tell?

“no” - > “num”

Post ID number from 4chan. Passed through as-is.


Ghostpost ID number for foolfuuka. Always zero.?


Thread IP number, always Post ID number of OP. “num” of thread OP (, ln. 196): “p.setThreadNum(pj.getResto() == 0 ? pj.getNo() : pj.getResto());”

“Time” ->“timestamp”

Timestamp of post. 4ch API provides as milliseconds since 1 JAN 1970 in USA NYC timezone. DB stores as ?(Probably milliseconds since 1 JAN 1970 UTC+0) (, ln. 202): p.setDate(DateUtils.adjustTimestampEpoch(pj.getTime(), DateUtils.NYC_TIMEZONE));

“resto” -> (If resto is 0, use value from “num”) -> op

Is this the OP of the thread? (, ln. 197): p.setOp(pj.getResto() == 0);

N/A -> Preview_orig

(, ln. 170): p.setPreviewOrig(pj.getTim() + "s.jpg");

“tn_w” -> “preview_w”

Width of media thumbnail (, ln. 193): p.setPreviewW(pj.getTnW());

“tn_h” -> “preview_h”

Height of media thumbnail. (, ln. 170): p.setPreviewH(pj.getTnH());

N/A -> media_filename

(, ln. 168): p.setMediaFilename(pj.getFilename() + pj.getExt());

“W” -> “media_w”

(, ln. 191): p.setMediaW(pj.getW());

“h” -> “media_h”

(, ln. 192): p.setMediaH(pj.getH());


(, ln. 190): p.setMediaSize(pj.getFsize());


(, ln. 189): p.setMediaHash(pj.getMd5());

N/A -> “Media_orig”

(, ln. 169): p.setMediaOrig(pj.getTim() + pj.getExt());


(, ln. 204): p.setSpoiler(pj.isSpoiler());

N/A -> “Deleted”

Set initially as false, then later updated if post is later absent from thread during subsequent updates. (, ln. 205):

#### “Capcode -> "Capcode"
(, ln. 173):

String capcode = pj.getCapcode(); if (capcode != null) { if (capcode.equals(“manager”) || capcode.equals(“Manager”)) { capcode = “G”; } else { capcode = capcode.substring(0, 1).toUpperCase(); } }” ```

“email” -> “Email”

(, ln. 199): p.setEmail(pj.getEmail());

“Name” -> (cleanSimple()) -> “Name”

(, ln. 200): p.setName(this.cleanSimple(pj.getName()));

“trip” -> “Trip”

(, ln. XX): p.setTrip(pj.getTrip());

“sub” -> (cleanSimple()) -> “Title”

(, ln. 198): p.setTitle(this.cleanSimple(pj.getSub()));

“com” -> (doClean) -> “Comment”

(, ln. 203): p.setComment(this.doClean(pj.getCom()));

N/A -> “Delpass”

TODO (, ln. XX): TODO

“sticky” -> “Sticky”

(, ln. 206): p.setSticky(pj.isSticky());

“closed”, “archived” -> “closed” AND (NOT “archived”)) -> “Locked”

(, ln. 207): p.setClosed(pj.isClosed() && !pj.isArchived()); (, ln. 78 - 86): this.insertQuery = String.format( (, ln. 236): insertStmt.setBoolean(c++, post.isClosed());

“id” -> “Poster_hash”

(, ln. 182):

String posterHash = pj.getId();
if(posterHash != null && posterHash.equals("Developer")) posterHash = "Dev";

“country” -> “Poster_country”

(, ln. 185-186):

String posterCountry = pj.getCountry();
if(posterCountry != null && (posterCountry.equals("XX") || posterCountry.equals("A1"))) posterCountry = null;

lots -> “exif”

(, ln. 212): p.setExif(this.cleanSimple(this.parseMeta(pj.getCom(), pj.getUniqueIps(), pj.getSince4pass(), pj.getTrollCountry()))); (, ln. 137): public String parseMeta(String text, Integer uniqueIps, Integer since4pass, String trollCountry) {

Images table values:

These seem to be handled by triggers that run on post insert. ### 4ch -> (asagi) -> DB

N/A -> (Incremental integer) -> “media_id”

This is simply an autoincrementing integer value. Set by DB engine if new image. Set by trigger if already-seen image. (Triggers.sql ln.119-139): - If the md5 is already in the DB media_id = LAST_INSERT_ID(media_id),

md5 -> (N/A) -> “media_hash”

The base64-encoded md5 hash of the media file as given by 4ch. ( ln.77-87) Omitted for brevity

N/A -> (Local filepath to full image) -> “media”

The relative path to the image on disk. (Triggers.sql ln.119-139): todo-codeblock

N/A -> (Local filepath to OP thumbnail) -> “preview_op”

The relative path to the image on disk. (Triggers.sql ln.119-139): todo-codeblock

N/A -> (Local filepath to reply thumbnail) -> “preview_reply”

The relative path to the image on disk. (Triggers.sql ln.119-139):

### N/A -> (incerementer) -> "total"
The number of posts that refer to this row.
(Triggers.sql) ln.123):

INSERT INTO "%%BOARD%%_images" (media_hash, media, preview_op, total)” (Triggers.sql ln.127):total = (total + 1),```

N/A -> (N/A) -> “banned”

Not set by Asagi, but observed to prevent downloading banned files (Triggers.sql ln.119-139):

##### Table definition
(Boards.sql ln.38-49): - _Table definition_

CREATE TABLE %%BOARD%%_images ( media_id SERIAL NOT NULL, media_hash character varying(25) NOT NULL, media character varying(20), preview_op character varying(20), preview_reply character varying(20), total integer NOT NULL DEFAULT ‘0’, banned smallint NOT NULL DEFAULT ‘0’, PRIMARY KEY (media_id), UNIQUE (media_hash) );

##### Image insert procedure

(Triggers.sql ln.119-139): - Image insert procedure

DROP PROCEDURE IF EXISTS “insert_image_%%BOARD%%”; CREATE PROCEDURE “insert_image_%%BOARD%%” (n_media_hash VARCHAR(25), n_media VARCHAR(20), n_preview VARCHAR(20), n_op INT) BEGIN IF n_op = 1 THEN INSERT INTO "%%BOARD%%_images" (media_hash, media, preview_op, total) VALUES (n_media_hash, n_media, n_preview, 1) ON DUPLICATE KEY UPDATE media_id = LAST_INSERT_ID(media_id), total = (total + 1), preview_op = COALESCE(preview_op, VALUES(preview_op)), media = COALESCE(media, VALUES(media)); ELSE INSERT INTO "%%BOARD%%_images" (media_hash, media, preview_reply, total) VALUES (n_media_hash, n_media, n_preview, 1) ON DUPLICATE KEY UPDATE media_id = LAST_INSERT_ID(media_id), total = (total + 1), preview_reply = COALESCE(preview_reply, VALUES(preview_reply)), media = COALESCE(media, VALUES(media)); END IF; END; ```

Data path:

4ch -> decode JSON -> make Post objects

API Date is retrieved from 4ch and put into TopicJson objects, ready for handling posts in each of those topics. ( ln .89): - Get 4ch API JSON String[] wgetReply = this.wgetText(this.linkThread(threadNum), lastMod); ( ln .97) - Decode JSON into TopicJson objects topicJson = GSON.fromJson(threadText, TopicJson.class); ( ln .93) V For a single topic, each post if decoded into a Post object Post object -> added to Topic object ( ln .93): - Create Topic object Topic t = null;

( ln .109): - OP t = this.makeThreadFromJson(pj);

( ln .116): - Reply t.addPost(this.makePostFromJson(pj));


( ln 303): topic = sourceBoard.getThread(newTopic, lastMod);


Image processed somehow?

Full image fetching begins

( ln 161): - Fullsize media downloader thread protected class MediaFetcher implements Runnable { ( lln. 169): - Grab from queue thing mediaPost = mediaUpdates.take(); ( lln. 173): - Try to handle the media for one post mediaLocalBoard.insertMedia(mediaPost, sourceBoard); ( ln. 201): - Handler for a post with media public void insertMedia(MediaPost h, Board source, boolean isPreview) throws ContentGetException, ContentStoreException, CfBicClearParseException { ( ln. 201): - Interact with DB for this media mediaRow = db.getMedia(h);

If there is information for this media in the DB, retreive it. If any new information exists about this media that is not already in the DB, add that to the DB entry. ( ln. 289): - Interact with DB for this media public synchronized Media getMedia(MediaPost post) throws ContentGetException, ContentStoreException, DBConnectionException {

( ln. 342-347): - Decide if media row needs an update

boolean mediaUpdate = media.getMedia() == null;
boolean previewOpUpdate = media.getPreviewOp() == null && post.isOp();
boolean previewReplyUpdate = media.getPreviewReply() == null && !post.isOp();
// Update media row in _images table when any of its entries are null and we actually have it
if(mediaUpdate || previewOpUpdate || previewReplyUpdate) {

( ln. 349-373): - Add values to DB for this media

if(mediaUpdate) {
updateMediaStmt.setString(1, post.getMedia());
updateMediaStmt.setString(2, post.getMediaHash());
if(previewOpUpdate) {
updatePreviewOpStmt.setString(1, post.getPreview());
updatePreviewOpStmt.setString(2, post.getMediaHash());
if(previewReplyUpdate) {
updatePreviewReplyStmt.setString(1, post.getPreview());
updatePreviewReplyStmt.setString(2, post.getMediaHash());

( ln. 62-66): - Preparing for selecting / updating media

selectMediaStmt = conn.prepareStatement(selectMediaQuery);
updateMediaStmt = conn.prepareStatement(updateMediaQuery);
updatePreviewOpStmt = conn.prepareStatement(updatePreviewOpQuery);
updatePreviewReplyStmt = conn.prepareStatement(updatePreviewReplyQuery);

( ln. 96-103): - SQL for selecting / updating media

this.selectMediaQuery = String.format("SELECT * FROM \"%s_images\" WHERE media_hash = ?",
this.updateMediaQuery = String.format("UPDATE \"%s_images\" SET media = ? WHERE media_hash = ?",
this.updatePreviewOpQuery = String.format("UPDATE \"%s_images\" SET preview_op = ? WHERE media_hash = ?",
this.updatePreviewReplyQuery = String.format("UPDATE \"%s_images\" SET preview_reply = ? WHERE media_hash = ?",

Threads table values:

Files of note: - Class definition boards.sql (ln.52) - Table definition triggers.sql

Functions of note:

(ln.217) “private Topic makeThreadFromJson(PostJson pj) throws ContentParseException {“

(Ln. 22) public Topic(int num, int omPosts, int omImages) {

Data flow: 4ch -> asagi -> DB

?Seems to be handled by DB triggers.?


Asagi source code used: Bibabon repo 2019-7 retrieved from with commit

Hayden source code :

Ayase Imageboard Archival Standard (Ayase)

The Ayase Imageboard Archival Standard was produced by the Bibliotheca Anonoma to handle the ever growing operations of Desuarchive and RebeccaBlackTech.

Reference Implementation

  • Operating System: CentOS/RHEL 8
  • Database: PostgreSQL
  • Scraper: Ena or Hydrus (.NET C#)
  • Middleware: Ayase (Python PyPy)
  • Frontends: 4chan X, Clover, iphone app



  • All files are to be named by shA256sum and file extension. This was chosen for the broad availability of hardware xtensions for the purpose nd its use by 8chan/vichan.
  • They are to be stored in double nested folders.


  • Ayase requires time to be stored in PostgreSQL datetimes, which also store timezones.
  • Only UTC should be used as the timezone for newly scraped data. The timezone support is not an excuse to store in other timezones.
  • The timezone support is only meant for compatibility purposes with prior Asagi data, given that they store time as US time (maybe Eastern) due to their past HTML scraping. Future scrapes are strongly advised not to replicate this behavior, local time should be up to the frontend to determine.

PostgreSQL Schema

if we GET json from the 4chan API, and always serve the same json to the user, why deconstruct and reconstruct into post focused sql records every time?

Elasticsearch Engine

A seperate elastic search engine kept in sync with, but independent from the sql server, will replace Sphinxsearch which queries the mysql db