Skip to content
4163Public

Repository files navigation

snap

Used In

Hocchan Archive / Drives
https://hocchan.netlify.app/archive/drive/g

Create an HTML copy of your file list

Take a snapshot of folders/files and turn it into a navigatable HTML file list.

This project is provided as-is. It's primarily built for my workflow, thus Windows only, there are no plans to support other operating systems.

The 📄snap-script.js files are awful please don't look at them :p.

Do not rename 📄snap.py when using to avoid having snap.py listed in your file list output.

📄snap.py requires Python to run. Local scans need no dependencies (tqdm will be used if it's installed for progress feedback). Cloud scans (Google Drive) require dependencies from requirements.txt. Install them via pip install -r requirements.txt.

References:

Cloud - Google Drive ··· Multi Page - JSON ··· Multi Page - DOM ··· Single File - DOM

Cloud - Google Drive

  • Works with all three variants below.
  • Accepts Service Account and Desktop app credentials from Google Cloud Console. Web application credentials won't work.

Workflow:

a. Put your Google Cloud credential 📄JSON file inside the .credentials/ folder.
b. Run 📄snap.py. When it finds credentials in .credentials/, it will ask which one to use, or let you scan the local directory instead.
c. If you're using a Desktop app credential, 📄snap.py copies the auth URL to your clipboard on the first run. Paste it in your browser to sign in, and it saves the token inside .credentials/ for next time. It then asks for a Google Drive folder URL/ID directly.
d. If you're using a Service Account credential, 📄snap.py lists folders shared with the service account so you can pick one, or paste a Google Drive folder URL/ID.
e. Once you pick a folder, it scans the Drive folder and generates the appropriate 📄JSON / 📄snap.html, or the single 📄snap_cloud.html file.

Multi Page - JSON

  • Recommended for public websites, has good performance and maintainability
  • Requires the use of a server because CORS policy blocks JSON fetches.
  • Requires JavaScript.
  • (Optional) Access to IndexedDB or In-Memory Cache.

1. Generate JSON and HTML snippets:

a. Copy and run 📄snap.py to wherever/whatever you want to create a file list of.
b. It will ask if you want to minify the JSON file, choose whichever you prefer (minified JSON is smaller in size).
c. After running and going through the setup, this will generate your 📄JSON file and 📄snap.html which has HTML snippets.

2. For your individual snap pages:

a. Define JSON file location in the HTML head via a meta element.
json file location

If no JSON file location is defined, the page will use a fallback JSON file (in this case 📄directories.json is defined as the fallback in 📄snap-script.js under object CONFIG), so be sure to set a jsonPath.
json file location

b. Define the JSON version in the head via a meta element.
json version

The JSON version can be found at the generated 📄snap.html.

c. Replace the entire <div class="header">...</div> block from your page.
html header

This can be found at the generated 📄snap.html.

d. Replace the entire <ul id="files" class="view-tiles" data-path="root">...</ul> block from your page.
html ul

Again, this can be found at the generated 📄snap.html.

If a JSON version is defined:

  • Compare the meta jsonVersion with the 📄JSON file used.
  • If the JSON versions are identical, prevent fetching the 📄JSON file on page load.
  • If the JSON versions are NOT identical keep fetching the 📄JSON file on page load.
  • Loop.

If a JSON version is NOT defined:

  • Keep fetching the 📄JSON file on page load.

Directory caching process:

  • Once 📄JSON is fetched tries to save JSON data in IndexedDB and uses that for subsequent navigations;
  • If IndexedDB cannot be accessed use In-Memory Cache for subsequent navigations.
  • If In-Memory Cache fails, do fetch requests to the 📄JSON file for every action/navigation (Very slow).

Multi Page - DOM

  • Can be used for public websites, a bit easier to setup and maintain with less performance
  • If database/file list is big (html file size of a few megabytes), page may load slow or freeze for a bit on page load.
  • Requires JavaScript.
  • (Optional) Access to In-Memory Cache.

1. Generate HTML snippet:

a. Copy and run 📄snap.py to wherever/whatever you want to create a file list of.
b. After running this will generate your 📄snap.html which has HTML snippets.

2. For your individual snap pages:

a. Replace the entire <div class="header">...</div> block from your page.
html header

This can be found at the generated 📄snap.html.

b. Replace the entire <ul id="files" class="view-tiles" data-path="root">...</ul> block from your page.
html ul

This can be found at the generated 📄snap.html.

c. Replace the entire <script id="dom-cache" type="application/json">...</script> block from your page.
html dom cache/json

Again, this can be found at the generated 📄snap.html.

Notice that depending on your text or code editor, this may display several hundred lines, as these blocks contain thousands of characters.
I have provided 📄_empty-script-block.html files which contain empty script blocks for this purpose.

json version

json version

Directory caching process:

  • If In-Memory Cache fails, script reads from <script id="dom-cache" type="application/json">...</script> for every action/navigation.

Single File - DOM

  • Recommended to be used for offline snapshots/archives of your file list.
  • Not recommended to be used for public websites, less performance and close to zero maintainability/customization.
  • If database/file list is big (html file size of a few megabytes), page may load slow or freeze for a bit on page load.
  • Requires JavaScript.

Generate HTML file list

- Copy and run 📄snap.py to whatever you want to create a file list of.

Directory caching process:

  • If In-Memory Cache fails, script reads from <script id="dom-cache" type="application/json">...</script> for every action/navigation.

Others

Feel free to edit or mess the CSS/HTML stylings but keep the necessary IDs, classes, and data variables used.

Custom icons:

On 📄snap-style.css add a new icon type under the /*hocchan union archive*/ comment;
json version

On 📄snap.py under the ICON_PRESETS dictionary, define a new icon type with the file formats it will use;
json version

'A': ['B'], 'A' is the .icon-A defined in 📄snap-style.css with the .icon- part omitted. And 'B' is the file format(s) that will use that icon preset.

By default any file format not defined will have no icon or can be set to use the default icon preset. This can be done in the 📄snap.py script by changing the USE_DEFAULT_PRESET variable to true.
json version

If you somehow want to edit the HTML/CSS/JS of Single File - DOM (why). The CSS is minified, just tidy that, and the JS is encoded in Base64, either decode that and then tidy. OR alternatively just use/edit the Multi Page - DOM CSS/JS.

Used by

Contributors

Languages