[
  {
    "path": ".git/HEAD",
    "content": "ref: refs/heads/main\n"
  },
  {
    "path": ".git/config",
    "content": "[core]\n\trepositoryformatversion = 1\n\tfilemode = true\n\tbare = false\n\tlogallrefupdates = true\n[remote \"origin\"]\n\turl = https://github.com/jc9108/eternity\n\ttagOpt = --no-tags\n\tfetch = +refs/heads/main:refs/remotes/origin/main\n\tpromisor = true\n\tpartialclonefilter = blob:limit=1048576\n[branch \"main\"]\n\tremote = origin\n\tmerge = refs/heads/main\n"
  },
  {
    "path": ".git/description",
    "content": "Unnamed repository; edit this file 'description' to name the repository.\n"
  },
  {
    "path": ".git/hooks/applypatch-msg.sample",
    "content": "#!/bin/sh\n#\n# An example hook script to check the commit log message taken by\n# applypatch from an e-mail message.\n#\n# The hook should exit with non-zero status after issuing an\n# appropriate message if it wants to stop the commit.  The hook is\n# allowed to edit the commit message file.\n#\n# To enable this hook, rename this file to \"applypatch-msg\".\n\n. git-sh-setup\ncommitmsg=\"$(git rev-parse --git-path hooks/commit-msg)\"\ntest -x \"$commitmsg\" && exec \"$commitmsg\" ${1+\"$@\"}\n:\n"
  },
  {
    "path": ".git/hooks/commit-msg.sample",
    "content": "#!/bin/sh\n#\n# An example hook script to check the commit log message.\n# Called by \"git commit\" with one argument, the name of the file\n# that has the commit message.  The hook should exit with non-zero\n# status after issuing an appropriate message if it wants to stop the\n# commit.  The hook is allowed to edit the commit message file.\n#\n# To enable this hook, rename this file to \"commit-msg\".\n\n# Uncomment the below to add a Signed-off-by line to the message.\n# Doing this in a hook is a bad idea in general, but the prepare-commit-msg\n# hook is more suited to it.\n#\n# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\\(.*>\\).*$/Signed-off-by: \\1/p')\n# grep -qs \"^$SOB\" \"$1\" || echo \"$SOB\" >> \"$1\"\n\n# This example catches duplicate Signed-off-by lines.\n\ntest \"\" = \"$(grep '^Signed-off-by: ' \"$1\" |\n\t sort | uniq -c | sed -e '/^[ \t]*1[ \t]/d')\" || {\n\techo >&2 Duplicate Signed-off-by lines.\n\texit 1\n}\n"
  },
  {
    "path": ".git/hooks/fsmonitor-watchman.sample",
    "content": "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\nuse IPC::Open2;\n\n# An example hook script to integrate Watchman\n# (https://facebook.github.io/watchman/) with git to speed up detecting\n# new and modified files.\n#\n# The hook is passed a version (currently 2) and last update token\n# formatted as a string and outputs to stdout a new update token and\n# all files that have been modified since the update token. Paths must\n# be relative to the root of the working tree and separated by a single NUL.\n#\n# To enable this hook, rename this file to \"query-watchman\" and set\n# 'git config core.fsmonitor .git/hooks/query-watchman'\n#\nmy ($version, $last_update_token) = @ARGV;\n\n# Uncomment for debugging\n# print STDERR \"$0 $version $last_update_token\\n\";\n\n# Check the hook interface version\nif ($version ne 2) {\n\tdie \"Unsupported query-fsmonitor hook version '$version'.\\n\" .\n\t    \"Falling back to scanning...\\n\";\n}\n\nmy $git_work_tree = get_working_dir();\n\nmy $retry = 1;\n\nmy $json_pkg;\neval {\n\trequire JSON::XS;\n\t$json_pkg = \"JSON::XS\";\n\t1;\n} or do {\n\trequire JSON::PP;\n\t$json_pkg = \"JSON::PP\";\n};\n\nlaunch_watchman();\n\nsub launch_watchman {\n\tmy $o = watchman_query();\n\tif (is_work_tree_watched($o)) {\n\t\toutput_result($o->{clock}, @{$o->{files}});\n\t}\n}\n\nsub output_result {\n\tmy ($clockid, @files) = @_;\n\n\t# Uncomment for debugging watchman output\n\t# open (my $fh, \">\", \".git/watchman-output.out\");\n\t# binmode $fh, \":utf8\";\n\t# print $fh \"$clockid\\n@files\\n\";\n\t# close $fh;\n\n\tbinmode STDOUT, \":utf8\";\n\tprint $clockid;\n\tprint \"\\0\";\n\tlocal $, = \"\\0\";\n\tprint @files;\n}\n\nsub watchman_clock {\n\tmy $response = qx/watchman clock \"$git_work_tree\"/;\n\tdie \"Failed to get clock id on '$git_work_tree'.\\n\" .\n\t\t\"Falling back to scanning...\\n\" if $? != 0;\n\n\treturn $json_pkg->new->utf8->decode($response);\n}\n\nsub watchman_query {\n\tmy $pid = open2(\\*CHLD_OUT, \\*CHLD_IN, 'watchman -j --no-pretty')\n\tor die \"open2() failed: $!\\n\" .\n\t\"Falling back to scanning...\\n\";\n\n\t# In the query expression below we're asking for names of files that\n\t# changed since $last_update_token but not from the .git folder.\n\t#\n\t# To accomplish this, we're using the \"since\" generator to use the\n\t# recency index to select candidate nodes and \"fields\" to limit the\n\t# output to file names only. Then we're using the \"expression\" term to\n\t# further constrain the results.\n\tmy $last_update_line = \"\";\n\tif (substr($last_update_token, 0, 1) eq \"c\") {\n\t\t$last_update_token = \"\\\"$last_update_token\\\"\";\n\t\t$last_update_line = qq[\\n\"since\": $last_update_token,];\n\t}\n\tmy $query = <<\"\tEND\";\n\t\t[\"query\", \"$git_work_tree\", {$last_update_line\n\t\t\t\"fields\": [\"name\"],\n\t\t\t\"expression\": [\"not\", [\"dirname\", \".git\"]]\n\t\t}]\n\tEND\n\n\t# Uncomment for debugging the watchman query\n\t# open (my $fh, \">\", \".git/watchman-query.json\");\n\t# print $fh $query;\n\t# close $fh;\n\n\tprint CHLD_IN $query;\n\tclose CHLD_IN;\n\tmy $response = do {local $/; <CHLD_OUT>};\n\n\t# Uncomment for debugging the watch response\n\t# open ($fh, \">\", \".git/watchman-response.json\");\n\t# print $fh $response;\n\t# close $fh;\n\n\tdie \"Watchman: command returned no output.\\n\" .\n\t\"Falling back to scanning...\\n\" if $response eq \"\";\n\tdie \"Watchman: command returned invalid output: $response\\n\" .\n\t\"Falling back to scanning...\\n\" unless $response =~ /^\\{/;\n\n\treturn $json_pkg->new->utf8->decode($response);\n}\n\nsub is_work_tree_watched {\n\tmy ($output) = @_;\n\tmy $error = $output->{error};\n\tif ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) {\n\t\t$retry--;\n\t\tmy $response = qx/watchman watch \"$git_work_tree\"/;\n\t\tdie \"Failed to make watchman watch '$git_work_tree'.\\n\" .\n\t\t    \"Falling back to scanning...\\n\" if $? != 0;\n\t\t$output = $json_pkg->new->utf8->decode($response);\n\t\t$error = $output->{error};\n\t\tdie \"Watchman: $error.\\n\" .\n\t\t\"Falling back to scanning...\\n\" if $error;\n\n\t\t# Uncomment for debugging watchman output\n\t\t# open (my $fh, \">\", \".git/watchman-output.out\");\n\t\t# close $fh;\n\n\t\t# Watchman will always return all files on the first query so\n\t\t# return the fast \"everything is dirty\" flag to git and do the\n\t\t# Watchman query just to get it over with now so we won't pay\n\t\t# the cost in git to look up each individual file.\n\t\tmy $o = watchman_clock();\n\t\t$error = $output->{error};\n\n\t\tdie \"Watchman: $error.\\n\" .\n\t\t\"Falling back to scanning...\\n\" if $error;\n\n\t\toutput_result($o->{clock}, (\"/\"));\n\t\t$last_update_token = $o->{clock};\n\n\t\teval { launch_watchman() };\n\t\treturn 0;\n\t}\n\n\tdie \"Watchman: $error.\\n\" .\n\t\"Falling back to scanning...\\n\" if $error;\n\n\treturn 1;\n}\n\nsub get_working_dir {\n\tmy $working_dir;\n\tif ($^O =~ 'msys' || $^O =~ 'cygwin') {\n\t\t$working_dir = Win32::GetCwd();\n\t\t$working_dir =~ tr/\\\\/\\//;\n\t} else {\n\t\trequire Cwd;\n\t\t$working_dir = Cwd::cwd();\n\t}\n\n\treturn $working_dir;\n}\n"
  },
  {
    "path": ".git/hooks/post-update.sample",
    "content": "#!/bin/sh\n#\n# An example hook script to prepare a packed repository for use over\n# dumb transports.\n#\n# To enable this hook, rename this file to \"post-update\".\n\nexec git update-server-info\n"
  },
  {
    "path": ".git/hooks/pre-applypatch.sample",
    "content": "#!/bin/sh\n#\n# An example hook script to verify what is about to be committed\n# by applypatch from an e-mail message.\n#\n# The hook should exit with non-zero status after issuing an\n# appropriate message if it wants to stop the commit.\n#\n# To enable this hook, rename this file to \"pre-applypatch\".\n\n. git-sh-setup\nprecommit=\"$(git rev-parse --git-path hooks/pre-commit)\"\ntest -x \"$precommit\" && exec \"$precommit\" ${1+\"$@\"}\n:\n"
  },
  {
    "path": ".git/hooks/pre-commit.sample",
    "content": "#!/bin/sh\n#\n# An example hook script to verify what is about to be committed.\n# Called by \"git commit\" with no arguments.  The hook should\n# exit with non-zero status after issuing an appropriate message if\n# it wants to stop the commit.\n#\n# To enable this hook, rename this file to \"pre-commit\".\n\nif git rev-parse --verify HEAD >/dev/null 2>&1\nthen\n\tagainst=HEAD\nelse\n\t# Initial commit: diff against an empty tree object\n\tagainst=$(git hash-object -t tree /dev/null)\nfi\n\n# If you want to allow non-ASCII filenames set this variable to true.\nallownonascii=$(git config --type=bool hooks.allownonascii)\n\n# Redirect output to stderr.\nexec 1>&2\n\n# Cross platform projects tend to avoid non-ASCII filenames; prevent\n# them from being added to the repository. We exploit the fact that the\n# printable range starts at the space character and ends with tilde.\nif [ \"$allownonascii\" != \"true\" ] &&\n\t# Note that the use of brackets around a tr range is ok here, (it's\n\t# even required, for portability to Solaris 10's /usr/bin/tr), since\n\t# the square bracket bytes happen to fall in the designated range.\n\ttest $(git diff-index --cached --name-only --diff-filter=A -z $against |\n\t  LC_ALL=C tr -d '[ -~]\\0' | wc -c) != 0\nthen\n\tcat <<\\EOF\nError: Attempt to add a non-ASCII file name.\n\nThis can cause problems if you want to work with people on other platforms.\n\nTo be portable it is advisable to rename the file.\n\nIf you know what you are doing you can disable this check using:\n\n  git config hooks.allownonascii true\nEOF\n\texit 1\nfi\n\n# If there are whitespace errors, print the offending file names and fail.\nexec git diff-index --check --cached $against --\n"
  },
  {
    "path": ".git/hooks/pre-merge-commit.sample",
    "content": "#!/bin/sh\n#\n# An example hook script to verify what is about to be committed.\n# Called by \"git merge\" with no arguments.  The hook should\n# exit with non-zero status after issuing an appropriate message to\n# stderr if it wants to stop the merge commit.\n#\n# To enable this hook, rename this file to \"pre-merge-commit\".\n\n. git-sh-setup\ntest -x \"$GIT_DIR/hooks/pre-commit\" &&\n        exec \"$GIT_DIR/hooks/pre-commit\"\n:\n"
  },
  {
    "path": ".git/hooks/pre-push.sample",
    "content": "#!/bin/sh\n\n# An example hook script to verify what is about to be pushed.  Called by \"git\n# push\" after it has checked the remote status, but before anything has been\n# pushed.  If this script exits with a non-zero status nothing will be pushed.\n#\n# This hook is called with the following parameters:\n#\n# $1 -- Name of the remote to which the push is being done\n# $2 -- URL to which the push is being done\n#\n# If pushing without using a named remote those arguments will be equal.\n#\n# Information about the commits which are being pushed is supplied as lines to\n# the standard input in the form:\n#\n#   <local ref> <local oid> <remote ref> <remote oid>\n#\n# This sample shows how to prevent push of commits where the log message starts\n# with \"WIP\" (work in progress).\n\nremote=\"$1\"\nurl=\"$2\"\n\nzero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')\n\nwhile read local_ref local_oid remote_ref remote_oid\ndo\n\tif test \"$local_oid\" = \"$zero\"\n\tthen\n\t\t# Handle delete\n\t\t:\n\telse\n\t\tif test \"$remote_oid\" = \"$zero\"\n\t\tthen\n\t\t\t# New branch, examine all commits\n\t\t\trange=\"$local_oid\"\n\t\telse\n\t\t\t# Update to existing branch, examine new commits\n\t\t\trange=\"$remote_oid..$local_oid\"\n\t\tfi\n\n\t\t# Check for WIP commit\n\t\tcommit=$(git rev-list -n 1 --grep '^WIP' \"$range\")\n\t\tif test -n \"$commit\"\n\t\tthen\n\t\t\techo >&2 \"Found WIP commit in $local_ref, not pushing\"\n\t\t\texit 1\n\t\tfi\n\tfi\ndone\n\nexit 0\n"
  },
  {
    "path": ".git/hooks/pre-rebase.sample",
    "content": "#!/bin/sh\n#\n# Copyright (c) 2006, 2008 Junio C Hamano\n#\n# The \"pre-rebase\" hook is run just before \"git rebase\" starts doing\n# its job, and can prevent the command from running by exiting with\n# non-zero status.\n#\n# The hook is called with the following parameters:\n#\n# $1 -- the upstream the series was forked from.\n# $2 -- the branch being rebased (or empty when rebasing the current branch).\n#\n# This sample shows how to prevent topic branches that are already\n# merged to 'next' branch from getting rebased, because allowing it\n# would result in rebasing already published history.\n\npublish=next\nbasebranch=\"$1\"\nif test \"$#\" = 2\nthen\n\ttopic=\"refs/heads/$2\"\nelse\n\ttopic=`git symbolic-ref HEAD` ||\n\texit 0 ;# we do not interrupt rebasing detached HEAD\nfi\n\ncase \"$topic\" in\nrefs/heads/??/*)\n\t;;\n*)\n\texit 0 ;# we do not interrupt others.\n\t;;\nesac\n\n# Now we are dealing with a topic branch being rebased\n# on top of master.  Is it OK to rebase it?\n\n# Does the topic really exist?\ngit show-ref -q \"$topic\" || {\n\techo >&2 \"No such branch $topic\"\n\texit 1\n}\n\n# Is topic fully merged to master?\nnot_in_master=`git rev-list --pretty=oneline ^master \"$topic\"`\nif test -z \"$not_in_master\"\nthen\n\techo >&2 \"$topic is fully merged to master; better remove it.\"\n\texit 1 ;# we could allow it, but there is no point.\nfi\n\n# Is topic ever merged to next?  If so you should not be rebasing it.\nonly_next_1=`git rev-list ^master \"^$topic\" ${publish} | sort`\nonly_next_2=`git rev-list ^master           ${publish} | sort`\nif test \"$only_next_1\" = \"$only_next_2\"\nthen\n\tnot_in_topic=`git rev-list \"^$topic\" master`\n\tif test -z \"$not_in_topic\"\n\tthen\n\t\techo >&2 \"$topic is already up to date with master\"\n\t\texit 1 ;# we could allow it, but there is no point.\n\telse\n\t\texit 0\n\tfi\nelse\n\tnot_in_next=`git rev-list --pretty=oneline ^${publish} \"$topic\"`\n\t/usr/bin/perl -e '\n\t\tmy $topic = $ARGV[0];\n\t\tmy $msg = \"* $topic has commits already merged to public branch:\\n\";\n\t\tmy (%not_in_next) = map {\n\t\t\t/^([0-9a-f]+) /;\n\t\t\t($1 => 1);\n\t\t} split(/\\n/, $ARGV[1]);\n\t\tfor my $elem (map {\n\t\t\t\t/^([0-9a-f]+) (.*)$/;\n\t\t\t\t[$1 => $2];\n\t\t\t} split(/\\n/, $ARGV[2])) {\n\t\t\tif (!exists $not_in_next{$elem->[0]}) {\n\t\t\t\tif ($msg) {\n\t\t\t\t\tprint STDERR $msg;\n\t\t\t\t\tundef $msg;\n\t\t\t\t}\n\t\t\t\tprint STDERR \" $elem->[1]\\n\";\n\t\t\t}\n\t\t}\n\t' \"$topic\" \"$not_in_next\" \"$not_in_master\"\n\texit 1\nfi\n\n<<\\DOC_END\n\nThis sample hook safeguards topic branches that have been\npublished from being rewound.\n\nThe workflow assumed here is:\n\n * Once a topic branch forks from \"master\", \"master\" is never\n   merged into it again (either directly or indirectly).\n\n * Once a topic branch is fully cooked and merged into \"master\",\n   it is deleted.  If you need to build on top of it to correct\n   earlier mistakes, a new topic branch is created by forking at\n   the tip of the \"master\".  This is not strictly necessary, but\n   it makes it easier to keep your history simple.\n\n * Whenever you need to test or publish your changes to topic\n   branches, merge them into \"next\" branch.\n\nThe script, being an example, hardcodes the publish branch name\nto be \"next\", but it is trivial to make it configurable via\n$GIT_DIR/config mechanism.\n\nWith this workflow, you would want to know:\n\n(1) ... if a topic branch has ever been merged to \"next\".  Young\n    topic branches can have stupid mistakes you would rather\n    clean up before publishing, and things that have not been\n    merged into other branches can be easily rebased without\n    affecting other people.  But once it is published, you would\n    not want to rewind it.\n\n(2) ... if a topic branch has been fully merged to \"master\".\n    Then you can delete it.  More importantly, you should not\n    build on top of it -- other people may already want to\n    change things related to the topic as patches against your\n    \"master\", so if you need further changes, it is better to\n    fork the topic (perhaps with the same name) afresh from the\n    tip of \"master\".\n\nLet's look at this example:\n\n\t\t   o---o---o---o---o---o---o---o---o---o \"next\"\n\t\t  /       /           /           /\n\t\t /   a---a---b A     /           /\n\t\t/   /               /           /\n\t       /   /   c---c---c---c B         /\n\t      /   /   /             \\         /\n\t     /   /   /   b---b C     \\       /\n\t    /   /   /   /             \\     /\n    ---o---o---o---o---o---o---o---o---o---o---o \"master\"\n\n\nA, B and C are topic branches.\n\n * A has one fix since it was merged up to \"next\".\n\n * B has finished.  It has been fully merged up to \"master\" and \"next\",\n   and is ready to be deleted.\n\n * C has not merged to \"next\" at all.\n\nWe would want to allow C to be rebased, refuse A, and encourage\nB to be deleted.\n\nTo compute (1):\n\n\tgit rev-list ^master ^topic next\n\tgit rev-list ^master        next\n\n\tif these match, topic has not merged in next at all.\n\nTo compute (2):\n\n\tgit rev-list master..topic\n\n\tif this is empty, it is fully merged to \"master\".\n\nDOC_END\n"
  },
  {
    "path": ".git/hooks/pre-receive.sample",
    "content": "#!/bin/sh\n#\n# An example hook script to make use of push options.\n# The example simply echoes all push options that start with 'echoback='\n# and rejects all pushes when the \"reject\" push option is used.\n#\n# To enable this hook, rename this file to \"pre-receive\".\n\nif test -n \"$GIT_PUSH_OPTION_COUNT\"\nthen\n\ti=0\n\twhile test \"$i\" -lt \"$GIT_PUSH_OPTION_COUNT\"\n\tdo\n\t\teval \"value=\\$GIT_PUSH_OPTION_$i\"\n\t\tcase \"$value\" in\n\t\techoback=*)\n\t\t\techo \"echo from the pre-receive-hook: ${value#*=}\" >&2\n\t\t\t;;\n\t\treject)\n\t\t\texit 1\n\t\tesac\n\t\ti=$((i + 1))\n\tdone\nfi\n"
  },
  {
    "path": ".git/hooks/prepare-commit-msg.sample",
    "content": "#!/bin/sh\n#\n# An example hook script to prepare the commit log message.\n# Called by \"git commit\" with the name of the file that has the\n# commit message, followed by the description of the commit\n# message's source.  The hook's purpose is to edit the commit\n# message file.  If the hook fails with a non-zero status,\n# the commit is aborted.\n#\n# To enable this hook, rename this file to \"prepare-commit-msg\".\n\n# This hook includes three examples. The first one removes the\n# \"# Please enter the commit message...\" help message.\n#\n# The second includes the output of \"git diff --name-status -r\"\n# into the message, just before the \"git status\" output.  It is\n# commented because it doesn't cope with --amend or with squashed\n# commits.\n#\n# The third example adds a Signed-off-by line to the message, that can\n# still be edited.  This is rarely a good idea.\n\nCOMMIT_MSG_FILE=$1\nCOMMIT_SOURCE=$2\nSHA1=$3\n\n/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' \"$COMMIT_MSG_FILE\"\n\n# case \"$COMMIT_SOURCE,$SHA1\" in\n#  ,|template,)\n#    /usr/bin/perl -i.bak -pe '\n#       print \"\\n\" . `git diff --cached --name-status -r`\n# \t if /^#/ && $first++ == 0' \"$COMMIT_MSG_FILE\" ;;\n#  *) ;;\n# esac\n\n# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\\(.*>\\).*$/Signed-off-by: \\1/p')\n# git interpret-trailers --in-place --trailer \"$SOB\" \"$COMMIT_MSG_FILE\"\n# if test -z \"$COMMIT_SOURCE\"\n# then\n#   /usr/bin/perl -i.bak -pe 'print \"\\n\" if !$first_line++' \"$COMMIT_MSG_FILE\"\n# fi\n"
  },
  {
    "path": ".git/hooks/push-to-checkout.sample",
    "content": "#!/bin/sh\n\n# An example hook script to update a checked-out tree on a git push.\n#\n# This hook is invoked by git-receive-pack(1) when it reacts to git\n# push and updates reference(s) in its repository, and when the push\n# tries to update the branch that is currently checked out and the\n# receive.denyCurrentBranch configuration variable is set to\n# updateInstead.\n#\n# By default, such a push is refused if the working tree and the index\n# of the remote repository has any difference from the currently\n# checked out commit; when both the working tree and the index match\n# the current commit, they are updated to match the newly pushed tip\n# of the branch. This hook is to be used to override the default\n# behaviour; however the code below reimplements the default behaviour\n# as a starting point for convenient modification.\n#\n# The hook receives the commit with which the tip of the current\n# branch is going to be updated:\ncommit=$1\n\n# It can exit with a non-zero status to refuse the push (when it does\n# so, it must not modify the index or the working tree).\ndie () {\n\techo >&2 \"$*\"\n\texit 1\n}\n\n# Or it can make any necessary changes to the working tree and to the\n# index to bring them to the desired state when the tip of the current\n# branch is updated to the new commit, and exit with a zero status.\n#\n# For example, the hook can simply run git read-tree -u -m HEAD \"$1\"\n# in order to emulate git fetch that is run in the reverse direction\n# with git push, as the two-tree form of git read-tree -u -m is\n# essentially the same as git switch or git checkout that switches\n# branches while keeping the local changes in the working tree that do\n# not interfere with the difference between the branches.\n\n# The below is a more-or-less exact translation to shell of the C code\n# for the default behaviour for git's push-to-checkout hook defined in\n# the push_to_deploy() function in builtin/receive-pack.c.\n#\n# Note that the hook will be executed from the repository directory,\n# not from the working tree, so if you want to perform operations on\n# the working tree, you will have to adapt your code accordingly, e.g.\n# by adding \"cd ..\" or using relative paths.\n\nif ! git update-index -q --ignore-submodules --refresh\nthen\n\tdie \"Up-to-date check failed\"\nfi\n\nif ! git diff-files --quiet --ignore-submodules --\nthen\n\tdie \"Working directory has unstaged changes\"\nfi\n\n# This is a rough translation of:\n#\n#   head_has_history() ? \"HEAD\" : EMPTY_TREE_SHA1_HEX\nif git cat-file -e HEAD 2>/dev/null\nthen\n\thead=HEAD\nelse\n\thead=$(git hash-object -t tree --stdin </dev/null)\nfi\n\nif ! git diff-index --quiet --cached --ignore-submodules $head --\nthen\n\tdie \"Working directory has staged changes\"\nfi\n\nif ! git read-tree -u -m \"$commit\"\nthen\n\tdie \"Could not update working tree to new HEAD\"\nfi\n"
  },
  {
    "path": ".git/hooks/sendemail-validate.sample",
    "content": "#!/bin/sh\n\n# An example hook script to validate a patch (and/or patch series) before\n# sending it via email.\n#\n# The hook should exit with non-zero status after issuing an appropriate\n# message if it wants to prevent the email(s) from being sent.\n#\n# To enable this hook, rename this file to \"sendemail-validate\".\n#\n# By default, it will only check that the patch(es) can be applied on top of\n# the default upstream branch without conflicts in a secondary worktree. After\n# validation (successful or not) of the last patch of a series, the worktree\n# will be deleted.\n#\n# The following config variables can be set to change the default remote and\n# remote ref that are used to apply the patches against:\n#\n#   sendemail.validateRemote (default: origin)\n#   sendemail.validateRemoteRef (default: HEAD)\n#\n# Replace the TODO placeholders with appropriate checks according to your\n# needs.\n\nvalidate_cover_letter () {\n\tfile=\"$1\"\n\t# TODO: Replace with appropriate checks (e.g. spell checking).\n\ttrue\n}\n\nvalidate_patch () {\n\tfile=\"$1\"\n\t# Ensure that the patch applies without conflicts.\n\tgit am -3 \"$file\" || return\n\t# TODO: Replace with appropriate checks for this patch\n\t# (e.g. checkpatch.pl).\n\ttrue\n}\n\nvalidate_series () {\n\t# TODO: Replace with appropriate checks for the whole series\n\t# (e.g. quick build, coding style checks, etc.).\n\ttrue\n}\n\n# main -------------------------------------------------------------------------\n\nif test \"$GIT_SENDEMAIL_FILE_COUNTER\" = 1\nthen\n\tremote=$(git config --default origin --get sendemail.validateRemote) &&\n\tref=$(git config --default HEAD --get sendemail.validateRemoteRef) &&\n\tworktree=$(mktemp --tmpdir -d sendemail-validate.XXXXXXX) &&\n\tgit worktree add -fd --checkout \"$worktree\" \"refs/remotes/$remote/$ref\" &&\n\tgit config --replace-all sendemail.validateWorktree \"$worktree\"\nelse\n\tworktree=$(git config --get sendemail.validateWorktree)\nfi || {\n\techo \"sendemail-validate: error: failed to prepare worktree\" >&2\n\texit 1\n}\n\nunset GIT_DIR GIT_WORK_TREE\ncd \"$worktree\" &&\n\nif grep -q \"^diff --git \" \"$1\"\nthen\n\tvalidate_patch \"$1\"\nelse\n\tvalidate_cover_letter \"$1\"\nfi &&\n\nif test \"$GIT_SENDEMAIL_FILE_COUNTER\" = \"$GIT_SENDEMAIL_FILE_TOTAL\"\nthen\n\tgit config --unset-all sendemail.validateWorktree &&\n\ttrap 'git worktree remove -ff \"$worktree\"' EXIT &&\n\tvalidate_series\nfi\n"
  },
  {
    "path": ".git/hooks/update.sample",
    "content": "#!/bin/sh\n#\n# An example hook script to block unannotated tags from entering.\n# Called by \"git receive-pack\" with arguments: refname sha1-old sha1-new\n#\n# To enable this hook, rename this file to \"update\".\n#\n# Config\n# ------\n# hooks.allowunannotated\n#   This boolean sets whether unannotated tags will be allowed into the\n#   repository.  By default they won't be.\n# hooks.allowdeletetag\n#   This boolean sets whether deleting tags will be allowed in the\n#   repository.  By default they won't be.\n# hooks.allowmodifytag\n#   This boolean sets whether a tag may be modified after creation. By default\n#   it won't be.\n# hooks.allowdeletebranch\n#   This boolean sets whether deleting branches will be allowed in the\n#   repository.  By default they won't be.\n# hooks.denycreatebranch\n#   This boolean sets whether remotely creating branches will be denied\n#   in the repository.  By default this is allowed.\n#\n\n# --- Command line\nrefname=\"$1\"\noldrev=\"$2\"\nnewrev=\"$3\"\n\n# --- Safety check\nif [ -z \"$GIT_DIR\" ]; then\n\techo \"Don't run this script from the command line.\" >&2\n\techo \" (if you want, you could supply GIT_DIR then run\" >&2\n\techo \"  $0 <ref> <oldrev> <newrev>)\" >&2\n\texit 1\nfi\n\nif [ -z \"$refname\" -o -z \"$oldrev\" -o -z \"$newrev\" ]; then\n\techo \"usage: $0 <ref> <oldrev> <newrev>\" >&2\n\texit 1\nfi\n\n# --- Config\nallowunannotated=$(git config --type=bool hooks.allowunannotated)\nallowdeletebranch=$(git config --type=bool hooks.allowdeletebranch)\ndenycreatebranch=$(git config --type=bool hooks.denycreatebranch)\nallowdeletetag=$(git config --type=bool hooks.allowdeletetag)\nallowmodifytag=$(git config --type=bool hooks.allowmodifytag)\n\n# check for no description\nprojectdesc=$(sed -e '1q' \"$GIT_DIR/description\")\ncase \"$projectdesc\" in\n\"Unnamed repository\"* | \"\")\n\techo \"*** Project description file hasn't been set\" >&2\n\texit 1\n\t;;\nesac\n\n# --- Check types\n# if $newrev is 0000...0000, it's a commit to delete a ref.\nzero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')\nif [ \"$newrev\" = \"$zero\" ]; then\n\tnewrev_type=delete\nelse\n\tnewrev_type=$(git cat-file -t $newrev)\nfi\n\ncase \"$refname\",\"$newrev_type\" in\n\trefs/tags/*,commit)\n\t\t# un-annotated tag\n\t\tshort_refname=${refname##refs/tags/}\n\t\tif [ \"$allowunannotated\" != \"true\" ]; then\n\t\t\techo \"*** The un-annotated tag, $short_refname, is not allowed in this repository\" >&2\n\t\t\techo \"*** Use 'git tag [ -a | -s ]' for tags you want to propagate.\" >&2\n\t\t\texit 1\n\t\tfi\n\t\t;;\n\trefs/tags/*,delete)\n\t\t# delete tag\n\t\tif [ \"$allowdeletetag\" != \"true\" ]; then\n\t\t\techo \"*** Deleting a tag is not allowed in this repository\" >&2\n\t\t\texit 1\n\t\tfi\n\t\t;;\n\trefs/tags/*,tag)\n\t\t# annotated tag\n\t\tif [ \"$allowmodifytag\" != \"true\" ] && git rev-parse $refname > /dev/null 2>&1\n\t\tthen\n\t\t\techo \"*** Tag '$refname' already exists.\" >&2\n\t\t\techo \"*** Modifying a tag is not allowed in this repository.\" >&2\n\t\t\texit 1\n\t\tfi\n\t\t;;\n\trefs/heads/*,commit)\n\t\t# branch\n\t\tif [ \"$oldrev\" = \"$zero\" -a \"$denycreatebranch\" = \"true\" ]; then\n\t\t\techo \"*** Creating a branch is not allowed in this repository\" >&2\n\t\t\texit 1\n\t\tfi\n\t\t;;\n\trefs/heads/*,delete)\n\t\t# delete branch\n\t\tif [ \"$allowdeletebranch\" != \"true\" ]; then\n\t\t\techo \"*** Deleting a branch is not allowed in this repository\" >&2\n\t\t\texit 1\n\t\tfi\n\t\t;;\n\trefs/remotes/*,commit)\n\t\t# tracking branch\n\t\t;;\n\trefs/remotes/*,delete)\n\t\t# delete tracking branch\n\t\tif [ \"$allowdeletebranch\" != \"true\" ]; then\n\t\t\techo \"*** Deleting a tracking branch is not allowed in this repository\" >&2\n\t\t\texit 1\n\t\tfi\n\t\t;;\n\t*)\n\t\t# Anything else (is there anything else?)\n\t\techo \"*** Update hook: unknown type of update to ref $refname of type $newrev_type\" >&2\n\t\texit 1\n\t\t;;\nesac\n\n# --- Finished\nexit 0\n"
  },
  {
    "path": ".git/info/exclude",
    "content": "# git ls-files --others --exclude-from=.git/info/exclude\n# Lines that start with '#' are comments.\n# For a project mostly in C, the following would be a good set of\n# exclude patterns (uncomment them if you want to use them):\n# *.[oa]\n# *~\n"
  },
  {
    "path": ".git/logs/HEAD",
    "content": "0000000000000000000000000000000000000000 6fdb4b2e78ba23a0c0a5c4e009441e7e17e43c04 appuser <appuser@7c99e0e64a07.(none)> 1778536176 +0000\tclone: from https://github.com/jc9108/eternity\n"
  },
  {
    "path": ".git/logs/refs/heads/main",
    "content": "0000000000000000000000000000000000000000 6fdb4b2e78ba23a0c0a5c4e009441e7e17e43c04 appuser <appuser@7c99e0e64a07.(none)> 1778536176 +0000\tclone: from https://github.com/jc9108/eternity\n"
  },
  {
    "path": ".git/logs/refs/remotes/origin/HEAD",
    "content": "0000000000000000000000000000000000000000 6fdb4b2e78ba23a0c0a5c4e009441e7e17e43c04 appuser <appuser@7c99e0e64a07.(none)> 1778536176 +0000\tclone: from https://github.com/jc9108/eternity\n"
  },
  {
    "path": ".git/objects/pack/pack-0615669dc08f9e04aa5251f0f02c684ee0619a11.promisor",
    "content": "6fdb4b2e78ba23a0c0a5c4e009441e7e17e43c04 refs/heads/main\n"
  },
  {
    "path": ".git/packed-refs",
    "content": "# pack-refs with: peeled fully-peeled sorted \n6fdb4b2e78ba23a0c0a5c4e009441e7e17e43c04 refs/remotes/origin/main\n"
  },
  {
    "path": ".git/refs/heads/main",
    "content": "6fdb4b2e78ba23a0c0a5c4e009441e7e17e43c04\n"
  },
  {
    "path": ".git/refs/remotes/origin/HEAD",
    "content": "ref: refs/remotes/origin/main\n"
  },
  {
    "path": ".git/shallow",
    "content": "6fdb4b2e78ba23a0c0a5c4e009441e7e17e43c04\n"
  },
  {
    "path": ".gitattributes",
    "content": "# https://github.com/github/linguist/blob/master/lib/linguist/languages.yml\r\n\r\nsql.mjs linguist-detectable=true\r\nsql.mjs linguist-language=SQL\r\n"
  },
  {
    "path": ".gitignore",
    "content": "# ignore\r\n\\#*\r\n.*\r\nnode_modules/\r\nbackups/\r\nlogs/\r\ntempfiles/\r\nbuild/\r\n\r\n# keep\r\n!.git*\r\n!.*rc\r\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU AFFERO GENERAL PUBLIC LICENSE\r\n                       Version 3, 19 November 2007\r\n\r\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\r\n Everyone is permitted to copy and distribute verbatim copies\r\n of this license document, but changing it is not allowed.\r\n\r\n                            Preamble\r\n\r\n  The GNU Affero General Public License is a free, copyleft license for\r\nsoftware and other kinds of works, specifically designed to ensure\r\ncooperation with the community in the case of network server software.\r\n\r\n  The licenses for most software and other practical works are designed\r\nto take away your freedom to share and change the works.  By contrast,\r\nour General Public Licenses are intended to guarantee your freedom to\r\nshare and change all versions of a program--to make sure it remains free\r\nsoftware for all its users.\r\n\r\n  When we speak of free software, we are referring to freedom, not\r\nprice.  Our General Public Licenses are designed to make sure that you\r\nhave the freedom to distribute copies of free software (and charge for\r\nthem if you wish), that you receive source code or can get it if you\r\nwant it, that you can change the software or use pieces of it in new\r\nfree programs, and that you know you can do these things.\r\n\r\n  Developers that use our General Public Licenses protect your rights\r\nwith two steps: (1) assert copyright on the software, and (2) offer\r\nyou this License which gives you legal permission to copy, distribute\r\nand/or modify the software.\r\n\r\n  A secondary benefit of defending all users' freedom is that\r\nimprovements made in alternate versions of the program, if they\r\nreceive widespread use, become available for other developers to\r\nincorporate.  Many developers of free software are heartened and\r\nencouraged by the resulting cooperation.  However, in the case of\r\nsoftware used on network servers, this result may fail to come about.\r\nThe GNU General Public License permits making a modified version and\r\nletting the public access it on a server without ever releasing its\r\nsource code to the public.\r\n\r\n  The GNU Affero General Public License is designed specifically to\r\nensure that, in such cases, the modified source code becomes available\r\nto the community.  It requires the operator of a network server to\r\nprovide the source code of the modified version running there to the\r\nusers of that server.  Therefore, public use of a modified version, on\r\na publicly accessible server, gives the public access to the source\r\ncode of the modified version.\r\n\r\n  An older license, called the Affero General Public License and\r\npublished by Affero, was designed to accomplish similar goals.  This is\r\na different license, not a version of the Affero GPL, but Affero has\r\nreleased a new version of the Affero GPL which permits relicensing under\r\nthis license.\r\n\r\n  The precise terms and conditions for copying, distribution and\r\nmodification follow.\r\n\r\n                       TERMS AND CONDITIONS\r\n\r\n  0. Definitions.\r\n\r\n  \"This License\" refers to version 3 of the GNU Affero General Public License.\r\n\r\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\r\nworks, such as semiconductor masks.\r\n\r\n  \"The Program\" refers to any copyrightable work licensed under this\r\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\r\n\"recipients\" may be individuals or organizations.\r\n\r\n  To \"modify\" a work means to copy from or adapt all or part of the work\r\nin a fashion requiring copyright permission, other than the making of an\r\nexact copy.  The resulting work is called a \"modified version\" of the\r\nearlier work or a work \"based on\" the earlier work.\r\n\r\n  A \"covered work\" means either the unmodified Program or a work based\r\non the Program.\r\n\r\n  To \"propagate\" a work means to do anything with it that, without\r\npermission, would make you directly or secondarily liable for\r\ninfringement under applicable copyright law, except executing it on a\r\ncomputer or modifying a private copy.  Propagation includes copying,\r\ndistribution (with or without modification), making available to the\r\npublic, and in some countries other activities as well.\r\n\r\n  To \"convey\" a work means any kind of propagation that enables other\r\nparties to make or receive copies.  Mere interaction with a user through\r\na computer network, with no transfer of a copy, is not conveying.\r\n\r\n  An interactive user interface displays \"Appropriate Legal Notices\"\r\nto the extent that it includes a convenient and prominently visible\r\nfeature that (1) displays an appropriate copyright notice, and (2)\r\ntells the user that there is no warranty for the work (except to the\r\nextent that warranties are provided), that licensees may convey the\r\nwork under this License, and how to view a copy of this License.  If\r\nthe interface presents a list of user commands or options, such as a\r\nmenu, a prominent item in the list meets this criterion.\r\n\r\n  1. Source Code.\r\n\r\n  The \"source code\" for a work means the preferred form of the work\r\nfor making modifications to it.  \"Object code\" means any non-source\r\nform of a work.\r\n\r\n  A \"Standard Interface\" means an interface that either is an official\r\nstandard defined by a recognized standards body, or, in the case of\r\ninterfaces specified for a particular programming language, one that\r\nis widely used among developers working in that language.\r\n\r\n  The \"System Libraries\" of an executable work include anything, other\r\nthan the work as a whole, that (a) is included in the normal form of\r\npackaging a Major Component, but which is not part of that Major\r\nComponent, and (b) serves only to enable use of the work with that\r\nMajor Component, or to implement a Standard Interface for which an\r\nimplementation is available to the public in source code form.  A\r\n\"Major Component\", in this context, means a major essential component\r\n(kernel, window system, and so on) of the specific operating system\r\n(if any) on which the executable work runs, or a compiler used to\r\nproduce the work, or an object code interpreter used to run it.\r\n\r\n  The \"Corresponding Source\" for a work in object code form means all\r\nthe source code needed to generate, install, and (for an executable\r\nwork) run the object code and to modify the work, including scripts to\r\ncontrol those activities.  However, it does not include the work's\r\nSystem Libraries, or general-purpose tools or generally available free\r\nprograms which are used unmodified in performing those activities but\r\nwhich are not part of the work.  For example, Corresponding Source\r\nincludes interface definition files associated with source files for\r\nthe work, and the source code for shared libraries and dynamically\r\nlinked subprograms that the work is specifically designed to require,\r\nsuch as by intimate data communication or control flow between those\r\nsubprograms and other parts of the work.\r\n\r\n  The Corresponding Source need not include anything that users\r\ncan regenerate automatically from other parts of the Corresponding\r\nSource.\r\n\r\n  The Corresponding Source for a work in source code form is that\r\nsame work.\r\n\r\n  2. Basic Permissions.\r\n\r\n  All rights granted under this License are granted for the term of\r\ncopyright on the Program, and are irrevocable provided the stated\r\nconditions are met.  This License explicitly affirms your unlimited\r\npermission to run the unmodified Program.  The output from running a\r\ncovered work is covered by this License only if the output, given its\r\ncontent, constitutes a covered work.  This License acknowledges your\r\nrights of fair use or other equivalent, as provided by copyright law.\r\n\r\n  You may make, run and propagate covered works that you do not\r\nconvey, without conditions so long as your license otherwise remains\r\nin force.  You may convey covered works to others for the sole purpose\r\nof having them make modifications exclusively for you, or provide you\r\nwith facilities for running those works, provided that you comply with\r\nthe terms of this License in conveying all material for which you do\r\nnot control copyright.  Those thus making or running the covered works\r\nfor you must do so exclusively on your behalf, under your direction\r\nand control, on terms that prohibit them from making any copies of\r\nyour copyrighted material outside their relationship with you.\r\n\r\n  Conveying under any other circumstances is permitted solely under\r\nthe conditions stated below.  Sublicensing is not allowed; section 10\r\nmakes it unnecessary.\r\n\r\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\r\n\r\n  No covered work shall be deemed part of an effective technological\r\nmeasure under any applicable law fulfilling obligations under article\r\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\r\nsimilar laws prohibiting or restricting circumvention of such\r\nmeasures.\r\n\r\n  When you convey a covered work, you waive any legal power to forbid\r\ncircumvention of technological measures to the extent such circumvention\r\nis effected by exercising rights under this License with respect to\r\nthe covered work, and you disclaim any intention to limit operation or\r\nmodification of the work as a means of enforcing, against the work's\r\nusers, your or third parties' legal rights to forbid circumvention of\r\ntechnological measures.\r\n\r\n  4. Conveying Verbatim Copies.\r\n\r\n  You may convey verbatim copies of the Program's source code as you\r\nreceive it, in any medium, provided that you conspicuously and\r\nappropriately publish on each copy an appropriate copyright notice;\r\nkeep intact all notices stating that this License and any\r\nnon-permissive terms added in accord with section 7 apply to the code;\r\nkeep intact all notices of the absence of any warranty; and give all\r\nrecipients a copy of this License along with the Program.\r\n\r\n  You may charge any price or no price for each copy that you convey,\r\nand you may offer support or warranty protection for a fee.\r\n\r\n  5. Conveying Modified Source Versions.\r\n\r\n  You may convey a work based on the Program, or the modifications to\r\nproduce it from the Program, in the form of source code under the\r\nterms of section 4, provided that you also meet all of these conditions:\r\n\r\n    a) The work must carry prominent notices stating that you modified\r\n    it, and giving a relevant date.\r\n\r\n    b) The work must carry prominent notices stating that it is\r\n    released under this License and any conditions added under section\r\n    7.  This requirement modifies the requirement in section 4 to\r\n    \"keep intact all notices\".\r\n\r\n    c) You must license the entire work, as a whole, under this\r\n    License to anyone who comes into possession of a copy.  This\r\n    License will therefore apply, along with any applicable section 7\r\n    additional terms, to the whole of the work, and all its parts,\r\n    regardless of how they are packaged.  This License gives no\r\n    permission to license the work in any other way, but it does not\r\n    invalidate such permission if you have separately received it.\r\n\r\n    d) If the work has interactive user interfaces, each must display\r\n    Appropriate Legal Notices; however, if the Program has interactive\r\n    interfaces that do not display Appropriate Legal Notices, your\r\n    work need not make them do so.\r\n\r\n  A compilation of a covered work with other separate and independent\r\nworks, which are not by their nature extensions of the covered work,\r\nand which are not combined with it such as to form a larger program,\r\nin or on a volume of a storage or distribution medium, is called an\r\n\"aggregate\" if the compilation and its resulting copyright are not\r\nused to limit the access or legal rights of the compilation's users\r\nbeyond what the individual works permit.  Inclusion of a covered work\r\nin an aggregate does not cause this License to apply to the other\r\nparts of the aggregate.\r\n\r\n  6. Conveying Non-Source Forms.\r\n\r\n  You may convey a covered work in object code form under the terms\r\nof sections 4 and 5, provided that you also convey the\r\nmachine-readable Corresponding Source under the terms of this License,\r\nin one of these ways:\r\n\r\n    a) Convey the object code in, or embodied in, a physical product\r\n    (including a physical distribution medium), accompanied by the\r\n    Corresponding Source fixed on a durable physical medium\r\n    customarily used for software interchange.\r\n\r\n    b) Convey the object code in, or embodied in, a physical product\r\n    (including a physical distribution medium), accompanied by a\r\n    written offer, valid for at least three years and valid for as\r\n    long as you offer spare parts or customer support for that product\r\n    model, to give anyone who possesses the object code either (1) a\r\n    copy of the Corresponding Source for all the software in the\r\n    product that is covered by this License, on a durable physical\r\n    medium customarily used for software interchange, for a price no\r\n    more than your reasonable cost of physically performing this\r\n    conveying of source, or (2) access to copy the\r\n    Corresponding Source from a network server at no charge.\r\n\r\n    c) Convey individual copies of the object code with a copy of the\r\n    written offer to provide the Corresponding Source.  This\r\n    alternative is allowed only occasionally and noncommercially, and\r\n    only if you received the object code with such an offer, in accord\r\n    with subsection 6b.\r\n\r\n    d) Convey the object code by offering access from a designated\r\n    place (gratis or for a charge), and offer equivalent access to the\r\n    Corresponding Source in the same way through the same place at no\r\n    further charge.  You need not require recipients to copy the\r\n    Corresponding Source along with the object code.  If the place to\r\n    copy the object code is a network server, the Corresponding Source\r\n    may be on a different server (operated by you or a third party)\r\n    that supports equivalent copying facilities, provided you maintain\r\n    clear directions next to the object code saying where to find the\r\n    Corresponding Source.  Regardless of what server hosts the\r\n    Corresponding Source, you remain obligated to ensure that it is\r\n    available for as long as needed to satisfy these requirements.\r\n\r\n    e) Convey the object code using peer-to-peer transmission, provided\r\n    you inform other peers where the object code and Corresponding\r\n    Source of the work are being offered to the general public at no\r\n    charge under subsection 6d.\r\n\r\n  A separable portion of the object code, whose source code is excluded\r\nfrom the Corresponding Source as a System Library, need not be\r\nincluded in conveying the object code work.\r\n\r\n  A \"User Product\" is either (1) a \"consumer product\", which means any\r\ntangible personal property which is normally used for personal, family,\r\nor household purposes, or (2) anything designed or sold for incorporation\r\ninto a dwelling.  In determining whether a product is a consumer product,\r\ndoubtful cases shall be resolved in favor of coverage.  For a particular\r\nproduct received by a particular user, \"normally used\" refers to a\r\ntypical or common use of that class of product, regardless of the status\r\nof the particular user or of the way in which the particular user\r\nactually uses, or expects or is expected to use, the product.  A product\r\nis a consumer product regardless of whether the product has substantial\r\ncommercial, industrial or non-consumer uses, unless such uses represent\r\nthe only significant mode of use of the product.\r\n\r\n  \"Installation Information\" for a User Product means any methods,\r\nprocedures, authorization keys, or other information required to install\r\nand execute modified versions of a covered work in that User Product from\r\na modified version of its Corresponding Source.  The information must\r\nsuffice to ensure that the continued functioning of the modified object\r\ncode is in no case prevented or interfered with solely because\r\nmodification has been made.\r\n\r\n  If you convey an object code work under this section in, or with, or\r\nspecifically for use in, a User Product, and the conveying occurs as\r\npart of a transaction in which the right of possession and use of the\r\nUser Product is transferred to the recipient in perpetuity or for a\r\nfixed term (regardless of how the transaction is characterized), the\r\nCorresponding Source conveyed under this section must be accompanied\r\nby the Installation Information.  But this requirement does not apply\r\nif neither you nor any third party retains the ability to install\r\nmodified object code on the User Product (for example, the work has\r\nbeen installed in ROM).\r\n\r\n  The requirement to provide Installation Information does not include a\r\nrequirement to continue to provide support service, warranty, or updates\r\nfor a work that has been modified or installed by the recipient, or for\r\nthe User Product in which it has been modified or installed.  Access to a\r\nnetwork may be denied when the modification itself materially and\r\nadversely affects the operation of the network or violates the rules and\r\nprotocols for communication across the network.\r\n\r\n  Corresponding Source conveyed, and Installation Information provided,\r\nin accord with this section must be in a format that is publicly\r\ndocumented (and with an implementation available to the public in\r\nsource code form), and must require no special password or key for\r\nunpacking, reading or copying.\r\n\r\n  7. Additional Terms.\r\n\r\n  \"Additional permissions\" are terms that supplement the terms of this\r\nLicense by making exceptions from one or more of its conditions.\r\nAdditional permissions that are applicable to the entire Program shall\r\nbe treated as though they were included in this License, to the extent\r\nthat they are valid under applicable law.  If additional permissions\r\napply only to part of the Program, that part may be used separately\r\nunder those permissions, but the entire Program remains governed by\r\nthis License without regard to the additional permissions.\r\n\r\n  When you convey a copy of a covered work, you may at your option\r\nremove any additional permissions from that copy, or from any part of\r\nit.  (Additional permissions may be written to require their own\r\nremoval in certain cases when you modify the work.)  You may place\r\nadditional permissions on material, added by you to a covered work,\r\nfor which you have or can give appropriate copyright permission.\r\n\r\n  Notwithstanding any other provision of this License, for material you\r\nadd to a covered work, you may (if authorized by the copyright holders of\r\nthat material) supplement the terms of this License with terms:\r\n\r\n    a) Disclaiming warranty or limiting liability differently from the\r\n    terms of sections 15 and 16 of this License; or\r\n\r\n    b) Requiring preservation of specified reasonable legal notices or\r\n    author attributions in that material or in the Appropriate Legal\r\n    Notices displayed by works containing it; or\r\n\r\n    c) Prohibiting misrepresentation of the origin of that material, or\r\n    requiring that modified versions of such material be marked in\r\n    reasonable ways as different from the original version; or\r\n\r\n    d) Limiting the use for publicity purposes of names of licensors or\r\n    authors of the material; or\r\n\r\n    e) Declining to grant rights under trademark law for use of some\r\n    trade names, trademarks, or service marks; or\r\n\r\n    f) Requiring indemnification of licensors and authors of that\r\n    material by anyone who conveys the material (or modified versions of\r\n    it) with contractual assumptions of liability to the recipient, for\r\n    any liability that these contractual assumptions directly impose on\r\n    those licensors and authors.\r\n\r\n  All other non-permissive additional terms are considered \"further\r\nrestrictions\" within the meaning of section 10.  If the Program as you\r\nreceived it, or any part of it, contains a notice stating that it is\r\ngoverned by this License along with a term that is a further\r\nrestriction, you may remove that term.  If a license document contains\r\na further restriction but permits relicensing or conveying under this\r\nLicense, you may add to a covered work material governed by the terms\r\nof that license document, provided that the further restriction does\r\nnot survive such relicensing or conveying.\r\n\r\n  If you add terms to a covered work in accord with this section, you\r\nmust place, in the relevant source files, a statement of the\r\nadditional terms that apply to those files, or a notice indicating\r\nwhere to find the applicable terms.\r\n\r\n  Additional terms, permissive or non-permissive, may be stated in the\r\nform of a separately written license, or stated as exceptions;\r\nthe above requirements apply either way.\r\n\r\n  8. Termination.\r\n\r\n  You may not propagate or modify a covered work except as expressly\r\nprovided under this License.  Any attempt otherwise to propagate or\r\nmodify it is void, and will automatically terminate your rights under\r\nthis License (including any patent licenses granted under the third\r\nparagraph of section 11).\r\n\r\n  However, if you cease all violation of this License, then your\r\nlicense from a particular copyright holder is reinstated (a)\r\nprovisionally, unless and until the copyright holder explicitly and\r\nfinally terminates your license, and (b) permanently, if the copyright\r\nholder fails to notify you of the violation by some reasonable means\r\nprior to 60 days after the cessation.\r\n\r\n  Moreover, your license from a particular copyright holder is\r\nreinstated permanently if the copyright holder notifies you of the\r\nviolation by some reasonable means, this is the first time you have\r\nreceived notice of violation of this License (for any work) from that\r\ncopyright holder, and you cure the violation prior to 30 days after\r\nyour receipt of the notice.\r\n\r\n  Termination of your rights under this section does not terminate the\r\nlicenses of parties who have received copies or rights from you under\r\nthis License.  If your rights have been terminated and not permanently\r\nreinstated, you do not qualify to receive new licenses for the same\r\nmaterial under section 10.\r\n\r\n  9. Acceptance Not Required for Having Copies.\r\n\r\n  You are not required to accept this License in order to receive or\r\nrun a copy of the Program.  Ancillary propagation of a covered work\r\noccurring solely as a consequence of using peer-to-peer transmission\r\nto receive a copy likewise does not require acceptance.  However,\r\nnothing other than this License grants you permission to propagate or\r\nmodify any covered work.  These actions infringe copyright if you do\r\nnot accept this License.  Therefore, by modifying or propagating a\r\ncovered work, you indicate your acceptance of this License to do so.\r\n\r\n  10. Automatic Licensing of Downstream Recipients.\r\n\r\n  Each time you convey a covered work, the recipient automatically\r\nreceives a license from the original licensors, to run, modify and\r\npropagate that work, subject to this License.  You are not responsible\r\nfor enforcing compliance by third parties with this License.\r\n\r\n  An \"entity transaction\" is a transaction transferring control of an\r\norganization, or substantially all assets of one, or subdividing an\r\norganization, or merging organizations.  If propagation of a covered\r\nwork results from an entity transaction, each party to that\r\ntransaction who receives a copy of the work also receives whatever\r\nlicenses to the work the party's predecessor in interest had or could\r\ngive under the previous paragraph, plus a right to possession of the\r\nCorresponding Source of the work from the predecessor in interest, if\r\nthe predecessor has it or can get it with reasonable efforts.\r\n\r\n  You may not impose any further restrictions on the exercise of the\r\nrights granted or affirmed under this License.  For example, you may\r\nnot impose a license fee, royalty, or other charge for exercise of\r\nrights granted under this License, and you may not initiate litigation\r\n(including a cross-claim or counterclaim in a lawsuit) alleging that\r\nany patent claim is infringed by making, using, selling, offering for\r\nsale, or importing the Program or any portion of it.\r\n\r\n  11. Patents.\r\n\r\n  A \"contributor\" is a copyright holder who authorizes use under this\r\nLicense of the Program or a work on which the Program is based.  The\r\nwork thus licensed is called the contributor's \"contributor version\".\r\n\r\n  A contributor's \"essential patent claims\" are all patent claims\r\nowned or controlled by the contributor, whether already acquired or\r\nhereafter acquired, that would be infringed by some manner, permitted\r\nby this License, of making, using, or selling its contributor version,\r\nbut do not include claims that would be infringed only as a\r\nconsequence of further modification of the contributor version.  For\r\npurposes of this definition, \"control\" includes the right to grant\r\npatent sublicenses in a manner consistent with the requirements of\r\nthis License.\r\n\r\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\r\npatent license under the contributor's essential patent claims, to\r\nmake, use, sell, offer for sale, import and otherwise run, modify and\r\npropagate the contents of its contributor version.\r\n\r\n  In the following three paragraphs, a \"patent license\" is any express\r\nagreement or commitment, however denominated, not to enforce a patent\r\n(such as an express permission to practice a patent or covenant not to\r\nsue for patent infringement).  To \"grant\" such a patent license to a\r\nparty means to make such an agreement or commitment not to enforce a\r\npatent against the party.\r\n\r\n  If you convey a covered work, knowingly relying on a patent license,\r\nand the Corresponding Source of the work is not available for anyone\r\nto copy, free of charge and under the terms of this License, through a\r\npublicly available network server or other readily accessible means,\r\nthen you must either (1) cause the Corresponding Source to be so\r\navailable, or (2) arrange to deprive yourself of the benefit of the\r\npatent license for this particular work, or (3) arrange, in a manner\r\nconsistent with the requirements of this License, to extend the patent\r\nlicense to downstream recipients.  \"Knowingly relying\" means you have\r\nactual knowledge that, but for the patent license, your conveying the\r\ncovered work in a country, or your recipient's use of the covered work\r\nin a country, would infringe one or more identifiable patents in that\r\ncountry that you have reason to believe are valid.\r\n\r\n  If, pursuant to or in connection with a single transaction or\r\narrangement, you convey, or propagate by procuring conveyance of, a\r\ncovered work, and grant a patent license to some of the parties\r\nreceiving the covered work authorizing them to use, propagate, modify\r\nor convey a specific copy of the covered work, then the patent license\r\nyou grant is automatically extended to all recipients of the covered\r\nwork and works based on it.\r\n\r\n  A patent license is \"discriminatory\" if it does not include within\r\nthe scope of its coverage, prohibits the exercise of, or is\r\nconditioned on the non-exercise of one or more of the rights that are\r\nspecifically granted under this License.  You may not convey a covered\r\nwork if you are a party to an arrangement with a third party that is\r\nin the business of distributing software, under which you make payment\r\nto the third party based on the extent of your activity of conveying\r\nthe work, and under which the third party grants, to any of the\r\nparties who would receive the covered work from you, a discriminatory\r\npatent license (a) in connection with copies of the covered work\r\nconveyed by you (or copies made from those copies), or (b) primarily\r\nfor and in connection with specific products or compilations that\r\ncontain the covered work, unless you entered into that arrangement,\r\nor that patent license was granted, prior to 28 March 2007.\r\n\r\n  Nothing in this License shall be construed as excluding or limiting\r\nany implied license or other defenses to infringement that may\r\notherwise be available to you under applicable patent law.\r\n\r\n  12. No Surrender of Others' Freedom.\r\n\r\n  If conditions are imposed on you (whether by court order, agreement or\r\notherwise) that contradict the conditions of this License, they do not\r\nexcuse you from the conditions of this License.  If you cannot convey a\r\ncovered work so as to satisfy simultaneously your obligations under this\r\nLicense and any other pertinent obligations, then as a consequence you may\r\nnot convey it at all.  For example, if you agree to terms that obligate you\r\nto collect a royalty for further conveying from those to whom you convey\r\nthe Program, the only way you could satisfy both those terms and this\r\nLicense would be to refrain entirely from conveying the Program.\r\n\r\n  13. Remote Network Interaction; Use with the GNU General Public License.\r\n\r\n  Notwithstanding any other provision of this License, if you modify the\r\nProgram, your modified version must prominently offer all users\r\ninteracting with it remotely through a computer network (if your version\r\nsupports such interaction) an opportunity to receive the Corresponding\r\nSource of your version by providing access to the Corresponding Source\r\nfrom a network server at no charge, through some standard or customary\r\nmeans of facilitating copying of software.  This Corresponding Source\r\nshall include the Corresponding Source for any work covered by version 3\r\nof the GNU General Public License that is incorporated pursuant to the\r\nfollowing paragraph.\r\n\r\n  Notwithstanding any other provision of this License, you have\r\npermission to link or combine any covered work with a work licensed\r\nunder version 3 of the GNU General Public License into a single\r\ncombined work, and to convey the resulting work.  The terms of this\r\nLicense will continue to apply to the part which is the covered work,\r\nbut the work with which it is combined will remain governed by version\r\n3 of the GNU General Public License.\r\n\r\n  14. Revised Versions of this License.\r\n\r\n  The Free Software Foundation may publish revised and/or new versions of\r\nthe GNU Affero General Public License from time to time.  Such new versions\r\nwill be similar in spirit to the present version, but may differ in detail to\r\naddress new problems or concerns.\r\n\r\n  Each version is given a distinguishing version number.  If the\r\nProgram specifies that a certain numbered version of the GNU Affero General\r\nPublic License \"or any later version\" applies to it, you have the\r\noption of following the terms and conditions either of that numbered\r\nversion or of any later version published by the Free Software\r\nFoundation.  If the Program does not specify a version number of the\r\nGNU Affero General Public License, you may choose any version ever published\r\nby the Free Software Foundation.\r\n\r\n  If the Program specifies that a proxy can decide which future\r\nversions of the GNU Affero General Public License can be used, that proxy's\r\npublic statement of acceptance of a version permanently authorizes you\r\nto choose that version for the Program.\r\n\r\n  Later license versions may give you additional or different\r\npermissions.  However, no additional obligations are imposed on any\r\nauthor or copyright holder as a result of your choosing to follow a\r\nlater version.\r\n\r\n  15. Disclaimer of Warranty.\r\n\r\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\r\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\r\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\r\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\r\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\r\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\r\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\r\n\r\n  16. Limitation of Liability.\r\n\r\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\r\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\r\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\r\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\r\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\r\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\r\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\r\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\r\nSUCH DAMAGES.\r\n\r\n  17. Interpretation of Sections 15 and 16.\r\n\r\n  If the disclaimer of warranty and limitation of liability provided\r\nabove cannot be given local legal effect according to their terms,\r\nreviewing courts shall apply local law that most closely approximates\r\nan absolute waiver of all civil liability in connection with the\r\nProgram, unless a warranty or assumption of liability accompanies a\r\ncopy of the Program in return for a fee.\r\n\r\n                     END OF TERMS AND CONDITIONS\r\n\r\n            How to Apply These Terms to Your New Programs\r\n\r\n  If you develop a new program, and you want it to be of the greatest\r\npossible use to the public, the best way to achieve this is to make it\r\nfree software which everyone can redistribute and change under these terms.\r\n\r\n  To do so, attach the following notices to the program.  It is safest\r\nto attach them to the start of each source file to most effectively\r\nstate the exclusion of warranty; and each file should have at least\r\nthe \"copyright\" line and a pointer to where the full notice is found.\r\n\r\n    <one line to give the program's name and a brief idea of what it does.>\r\n    Copyright (C) <year>  <name of author>\r\n\r\n    This program is free software: you can redistribute it and/or modify\r\n    it under the terms of the GNU Affero General Public License as published by\r\n    the Free Software Foundation, either version 3 of the License, or\r\n    (at your option) any later version.\r\n\r\n    This program is distributed in the hope that it will be useful,\r\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n    GNU Affero General Public License for more details.\r\n\r\n    You should have received a copy of the GNU Affero General Public License\r\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\r\n\r\nAlso add information on how to contact you by electronic and paper mail.\r\n\r\n  If your software can interact with users remotely through a computer\r\nnetwork, you should also make sure that it provides a way for users to\r\nget its source.  For example, if your program is a web application, its\r\ninterface could display a \"Source\" link that leads users to an archive\r\nof the code.  There are many ways you could offer source, and different\r\nsolutions will be better for different programs; see section 13 for the\r\nspecific requirements.\r\n\r\n  You should also get your employer (if you work as a programmer) or school,\r\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\r\nFor more information on this, and how to apply and follow the GNU AGPL, see\r\n<https://www.gnu.org/licenses/>.\r\n"
  },
  {
    "path": "README.md",
    "content": "# [eternity](https://eternity.portals.sh)\r\n\r\nbypass Reddit's 1000-item listing limits by externally storing your Reddit items (saved, created, upvoted, downvoted, hidden) in your own database\r\n\r\n- features::\r\n\t- new items auto-sync\r\n\t- synced items not affected by Reddit deletion\r\n\t- search for items\r\n\t- filter by subreddit\r\n\t- unsave/delete/unvote/unhide items from Reddit directly on eternity\r\n\t- import csv data from [Reddit data request](https://www.reddit.com/settings/data-request)\r\n\t- export data as json\r\n- [demo](https://www.youtube.com/watch?v=4pxXM98ewIc)\r\n- [Firebase setup guide](https://www.youtube.com/watch?v=KPxppovc56A)\r\n- [selfhosted version](https://github.com/jc9108/expanse)\r\n"
  },
  {
    "path": "SPONSORS.md",
    "content": "# sponsors\r\n\r\nsupport this project by becoming a [sponsor](https://github.com/sponsors/jc9108)\r\n\r\n- big thanks to::\r\n\t- [jmorlin](https://github.com/jmorlin)\r\n\t- [rubik11](https://github.com/rubik11)\r\n"
  },
  {
    "path": "backend/.npmrc",
    "content": "engine-strict=true\r\nunsafe-perm=true\r\nsave-exact=true\r\n"
  },
  {
    "path": "backend/controller/server.mjs",
    "content": "const backend = process.cwd();\r\nimport * as dotenv from \"dotenv\";\r\ndotenv.config({\r\n\tpath: `${backend}/.env_${process.env.RUN}`\r\n});\r\n\r\nconst file = await import(`${backend}/model/file.mjs`);\r\nconst sql = await import(`${backend}/model/sql.mjs`);\r\nconst firebase = await import(`${backend}/model/firebase.mjs`);\r\nconst cryptr = await import(`${backend}/model/cryptr.mjs`);\r\nconst user = await import(`${backend}/model/user.mjs`);\r\nconst email = await import(`${backend}/model/email.mjs`);\r\nconst utils = await import(`${backend}/model/utils.mjs`);\r\n\r\nimport * as socket_io_server from \"socket.io\";\r\nimport * as socket_io_client from \"socket.io-client\";\r\nimport express from \"express\";\r\nimport http from \"http\";\r\nimport cookie_session from \"cookie-session\";\r\nimport passport from \"passport\";\r\nimport passport_reddit from \"passport-reddit\";\r\nimport crypto from \"crypto\";\r\nimport filesystem from \"fs\";\r\nimport fileupload from \"express-fileupload\";\r\n\r\nlet domain_request_info = null;\r\n\r\nconst app = express();\r\nconst server = http.createServer(app);\r\nconst io = new socket_io_server.Server(server, {\r\n\tcors: (process.env.RUN == \"dev\" ? {origin: \"*\"} : null),\r\n\tmaxHttpBufferSize: 1000000 // 1mb in bytes\r\n});\r\nconst app_socket = socket_io_client.io(\"http://localhost:1026\", {\r\n\tautoConnect: false,\r\n\treconnect: true,\r\n\textraHeaders: {\r\n\t\tapp: \"eternity\",\r\n\t\tsecret: process.env.LOCAL_SOCKETS_SECRET\r\n\t}\r\n});\r\n\r\nconst frontend = backend.replace(\"backend\", \"frontend\");\r\n\r\nconst allowed_users = new Set(process.env.ALLOWED_USERS.split(\", \"));\r\nconst denied_users = new Set(process.env.DENIED_USERS.split(\", \"));\r\n\r\nawait file.init();\r\nawait sql.init_db();\r\nsql.cycle_backup_db();\r\nawait user.fill_usernames_to_socket_ids();\r\nuser.cycle_update_all(io);\r\n\r\napp.use(fileupload({\r\n\tlimits: {\r\n\t\tfileSize: 3072 // 3kb in binary bytes. firebase service account key files should be ~2.35kb\r\n\t}\r\n}));\r\n\r\napp.use(\"/\", express.static(`${frontend}/build/`));\r\n\r\npassport.use(new passport_reddit.Strategy({\r\n\tclientID: process.env.REDDIT_APP_ID,\r\n\tclientSecret: process.env.REDDIT_APP_SECRET,\r\n\tcallbackURL: process.env.REDDIT_APP_REDIRECT,\r\n\tscope: [\"identity\", \"history\", \"read\", \"save\", \"edit\", \"vote\", \"report\"] // https://github.com/reddit-archive/reddit/wiki/OAuth2 \"scope values\", https://www.reddit.com/dev/api/oauth\r\n}, async (user_access_token, user_refresh_token, user_profile, done) => { // http://www.passportjs.org/docs/configure \"verify callback\"\r\n\tconst u = new user.User(user_profile.name, user_refresh_token);\r\n\r\n\ttry {\r\n\t\tawait u.save();\r\n\t\treturn done(null, u); // passes the user to serializeUser\r\n\t} catch (err) {\r\n\t\tconsole.error(err);\r\n\t}\r\n}));\r\npassport.serializeUser((u, done) => done(null, u.username)); // store user's username into session cookie\r\npassport.deserializeUser(async (username, done) => { // get user from db, specified by username in session cookie\r\n\ttry {\r\n\t\tconst u = await user.get(username);\r\n\t\tdone(null, u);\r\n\t\tconsole.log(`deserialized user (${username})`);\r\n\t} catch (err) {\r\n\t\tconsole.log(`deserialize error (${username})`);\r\n\t\tconsole.error(err);\r\n\t\tdone(err, null);\r\n\t}\r\n});\r\nprocess.nextTick(() => { // handle any deserializeUser errors here\r\n\tapp.use((err, req, res, next) => {\r\n\t\tif (err) {\r\n\t\t\tconsole.error(err);\r\n\r\n\t\t\tconst username = req.session.passport.user;\r\n\t\t\tdelete user.usernames_to_socket_ids[username];\r\n\t\t\t\r\n\t\t\treq.session = null; // destroy login session\r\n\t\t\tconsole.log(`destroyed session (${username})`);\r\n\t\t\treq.logout();\r\n\r\n\t\t\tres.status(401).sendFile(`${frontend}/build/index.html`);\r\n\t\t} else {\r\n\t\t\tnext();\r\n\t\t}\r\n\t});\r\n});\r\napp.use(express.urlencoded({\r\n\textended: false\r\n}));\r\napp.use(cookie_session({ // https://github.com/expressjs/cookie-session\r\n\tname: \"eternity_session\",\r\n\tpath: \"/\",\r\n\tsecret: process.env.SESSION_SECRET,\r\n\tsigned: true,\r\n\thttpOnly: true,\r\n\toverwrite: true,\r\n\tsameSite: \"lax\",\r\n\tmaxAge: 1000*60*60*24*30\r\n}));\r\napp.use((req, res, next) => { // rolling session: https://github.com/expressjs/cookie-session#extending-the-session-expiration\r\n\treq.session.nowInMinutes = Math.floor(Date.now() / 60000);\r\n\tnext();\r\n});\r\napp.use(passport.initialize());\r\napp.use(passport.session());\r\n\r\napp.get(\"/login\", (req, res, next) => {\r\n\tpassport.authenticate(\"reddit\", { // https://github.com/Slotos/passport-reddit/blob/9717523d3d3f58447fee765c0ad864592efb67e8/examples/login/app.js#L86\r\n\t\tstate: req.session.state = crypto.randomBytes(32).toString(\"hex\"),\r\n\t\tduration: \"permanent\"\r\n\t})(req, res, next);\r\n});\r\n\r\napp.get(\"/callback\", (req, res, next) => {\r\n\tif (req.query.state == req.session.state) {\r\n\t\tpassport.authenticate(\"reddit\", async (err, u, info) => {\r\n\t\t\tif (err || !u) {\r\n\t\t\t\tres.redirect(302, \"/logout\");\r\n\t\t\t} else if ((allowed_users.has(\"*\") && denied_users.has(u.username)) || (!allowed_users.has(\"*\") && !allowed_users.has(u.username)) || (denied_users.has(\"*\") && !allowed_users.has(u.username))) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tawait u.purge();\r\n\t\t\t\t\tres.redirect(302, \"/logout\");\r\n\t\t\t\t\tconsole.log(`denied user (${u.username})`);\r\n\t\t\t\t} catch (err) {\r\n\t\t\t\t\tconsole.error(err);\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\treq.login(u, () => {\r\n\t\t\t\t\tres.redirect(302, \"/\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t})(req, res, next);\r\n\t} else {\r\n\t\tres.redirect(302, \"/logout\");\r\n\t}\r\n});\r\n\r\napp.get(\"/authentication_check\", (req, res) => {\r\n\tif (req.isAuthenticated()) {\r\n\t\tuser.usernames_to_socket_ids[req.user.username] = req.query.socket_id;\r\n\t\tuser.socket_ids_to_usernames[req.query.socket_id] = req.user.username;\r\n\r\n\t\tlet page = null;\r\n\r\n\t\tif (req.user.last_updated_epoch) {\r\n\t\t\tpage = \"access\";\r\n\t\t} else if (req.user.firebase_service_acc_key_encrypted) {\r\n\t\t\tpage = \"loading\";\r\n\t\t} else {\r\n\t\t\tpage = \"unlock\";\r\n\t\t}\r\n\r\n\t\tres.send({\r\n\t\t\tusername: req.user.username,\r\n\t\t\tuse_page: page\r\n\t\t});\r\n\t} else {\r\n\t\tres.send({\r\n\t\t\tuse_page: \"landing\"\r\n\t\t});\r\n\t}\r\n});\r\n\r\napp.post(\"/upload\", (req, res) => {\r\n\tif (req.isAuthenticated()) {\r\n\t\t(req.files.key ? req.files.key.mv(`${backend}/tempfiles/${req.user.username}_firebase_service_acc_key.json`).catch((err) => console.error(err)) : null);\r\n\t\tres.end();\r\n\t} else {\r\n\t\tres.status(401).sendFile(`${frontend}/build/index.html`);\r\n\t}\r\n});\r\n\r\napp.get(\"/logout\", (req, res) => {\r\n\tif (req.isAuthenticated()) {\r\n\t\treq.logout();\r\n\t\tres.redirect(302, \"/\");\r\n\t} else {\r\n\t\tres.status(401).sendFile(`${frontend}/build/index.html`);\r\n\t}\r\n});\r\n\r\napp.get(\"/purge\", async (req, res) => {\r\n\tif (req.isAuthenticated() && req.query.socket_id == user.usernames_to_socket_ids[req.user.username]) {\r\n\t\ttry {\r\n\t\t\tawait req.user.purge();\r\n\t\t\treq.logout();\r\n\t\t\tres.send(\"success\");\r\n\t\t} catch (err) {\r\n\t\t\tconsole.error(err);\r\n\t\t\tres.send(\"error\");\r\n\t\t}\r\n\t} else {\r\n\t\tres.status(401).sendFile(`${frontend}/build/index.html`);\r\n\t}\r\n});\r\n\r\napp.all(\"*\", (req, res) => {\r\n\tres.status(404).sendFile(`${frontend}/build/index.html`);\r\n});\r\n\r\nio.on(\"connect\", (socket) => {\r\n\tconsole.log(`socket (${socket.id}) connected`);\r\n\r\n\tsocket.username = null;\r\n\tsocket.firebase_instances_created = false; // clientside firebase instances (app, auth, db)\r\n\r\n\tsocket.on(\"layout mounted\", () => {\r\n\t\tio.to(socket.id).emit(\"update domain request info\", domain_request_info);\r\n\t});\r\n\r\n\tsocket.on(\"route\", (route) => {\r\n\t\tswitch (route) {\r\n\t\t\tcase \"index\":\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"about\":\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t});\r\n\r\n\tsocket.on(\"page\", async (page) => {\r\n\t\tlet u = null;\r\n\r\n\t\tswitch (page) {\r\n\t\t\tcase \"landing\":\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"unlock\":\r\n\t\t\t\tsocket.username = user.socket_ids_to_usernames[socket.id];\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"loading\":\r\n\t\t\t\tsocket.username = user.socket_ids_to_usernames[socket.id];\r\n\t\t\t\ttry {\r\n\t\t\t\t\tu = await user.get(socket.username);\r\n\t\t\t\t\tawait u.update(io, socket.id);\r\n\t\t\t\t} catch (err) {\r\n\t\t\t\t\tconsole.error(err);\r\n\t\t\t\t\t(u && u.firebase_app ? firebase.free_app(u.firebase_app).catch((err) => console.error(err)) : null);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"access\":\r\n\t\t\t\tsocket.username = user.socket_ids_to_usernames[socket.id];\r\n\t\t\t\ttry {\r\n\t\t\t\t\tu = await user.get(socket.username);\r\n\r\n\t\t\t\t\tio.to(socket.id).emit(\"store last updated epoch\", u.last_updated_epoch);\r\n\r\n\t\t\t\t\tsql.update_user(u.username, {\r\n\t\t\t\t\t\tlast_active_epoch: u.last_active_epoch = utils.now_epoch()\r\n\t\t\t\t\t}).catch((err) => console.error(err));\r\n\t\t\t\t} catch (err) {\r\n\t\t\t\t\tconsole.error(err);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\r\n\t\tif (u && !socket.firebase_instances_created) {\r\n\t\t\ttry {\r\n\t\t\t\tconst app = firebase.create_app(JSON.parse(cryptr.decrypt(u.firebase_service_acc_key_encrypted)), JSON.parse(cryptr.decrypt(u.firebase_web_app_config_encrypted)).databaseURL, u.username);\r\n\t\t\t\tconst auth_token = await firebase.create_new_auth_token(app);\r\n\t\t\t\tfirebase.free_app(app).catch((err) => console.error(err));\r\n\t\r\n\t\t\t\tio.to(socket.id).emit(\"create firebase instances\", JSON.parse(cryptr.decrypt(u.firebase_web_app_config_encrypted)), auth_token);\r\n\t\t\t\tsocket.firebase_instances_created = true;\r\n\t\t\t} catch (err) {\r\n\t\t\t\tconsole.error(err);\r\n\t\t\t}\r\n\t\t}\r\n\t});\r\n\r\n\tsocket.on(\"validate firebase info\", async (web_app_config) => {\r\n\t\ttry {\r\n\t\t\tconst key_path = `${backend}/tempfiles/${socket.username}_firebase_service_acc_key.json`;\r\n\t\t\tconst key_string = await filesystem.promises.readFile(key_path, \"utf-8\");\r\n\t\t\tconst key_obj = JSON.parse(key_string);\r\n\t\r\n\t\t\tif (!(key_obj.type && key_obj.type == \"service_account\") && key_obj.project_id && key_obj.private_key_id && key_obj.private_key && key_obj.client_email && key_obj.client_id && key_obj.auth_uri && key_obj.token_uri && key_obj.auth_provider_x509_cert_url && key_obj.client_x509_cert_url) {\r\n\t\t\t\tio.to(socket.id).emit(\"alert\", \"firebase\", \"validation failed: incorrect Firebase project service account key\", \"danger\");\r\n\t\t\t\tawait filesystem.promises.unlink(key_path);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif (!(web_app_config.databaseURL && web_app_config.databaseURL.includes(\"firebase\") && web_app_config.apiKey && web_app_config.authDomain && web_app_config.projectId && web_app_config.storageBucket && web_app_config.messagingSenderId && web_app_config.appId)) {\r\n\t\t\t\tio.to(socket.id).emit(\"alert\", \"firebase\", \"validation failed: incorrect Firebase web app config\", \"danger\");\r\n\t\t\t\tawait filesystem.promises.unlink(key_path);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\r\n\t\t\ttry {\r\n\t\t\t\tconst app = firebase.create_app(key_obj, web_app_config.databaseURL, socket.username);\r\n\t\t\t\tconst db = firebase.get_db(app);\r\n\t\t\t\tconst db_is_empty = await firebase.is_empty(db);\r\n\t\t\t\tfirebase.free_app(app).catch((err) => console.error(err));\r\n\t\t\t\tif (!db_is_empty) {\r\n\t\t\t\t\tio.to(socket.id).emit(\"alert\", \"firebase\", \"validation failed: database not empty\", \"danger\");\r\n\t\t\t\t\tawait filesystem.promises.unlink(key_path);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t} catch (err) {\r\n\t\t\t\tconsole.error(err);\r\n\t\t\t\tio.to(socket.id).emit(\"alert\", \"firebase\", \"validation failed: could not check database\", \"danger\");\r\n\t\t\t\tawait filesystem.promises.unlink(key_path);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\r\n\t\t\tawait filesystem.promises.unlink(key_path);\r\n\t\r\n\t\t\tsocket.firebase_service_acc_key_encrypted = cryptr.encrypt(JSON.stringify(key_obj));\r\n\t\t\tsocket.firebase_web_app_config_encrypted = cryptr.encrypt(JSON.stringify(web_app_config));\r\n\t\t\tio.to(socket.id).emit(\"alert\", \"firebase\", \"validation success\", \"success\");\r\n\t\t\tio.to(socket.id).emit(\"disable button\", \"validate\");\r\n\t\r\n\t\t\t(socket.firebase_service_acc_key_encrypted && socket.firebase_web_app_config_encrypted && socket.verified_email ? io.to(socket.id).emit(\"enable button\", \"save_and_continue\") : null);\r\n\t\t} catch (err) {\r\n\t\t\tconsole.error(err);\r\n\t\t}\r\n\t});\r\n\r\n\tsocket.on(\"confirm email\", async (email_addr) => {\r\n\t\temail_addr = email_addr.trim();\r\n\r\n\t\tif (!(email_addr && email_addr.includes(\"@\") && email_addr.includes(\".\") && email_addr.length >= 7)) {\r\n\t\t\tio.to(socket.id).emit(\"alert\", \"email\", \"this is not an email address\", \"danger\");\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tio.to(socket.id).emit(\"disable button\", \"confirm\");\r\n\t\t\r\n\t\tconst obj = {\r\n\t\t\tusername: socket.username,\r\n\t\t\temail_encrypted: socket.email_encrypted = cryptr.encrypt(email_addr)\r\n\t\t};\r\n\t\temail.send(obj, \"verify your email\", `<big>${socket.id.replace(/(\\W)|(_)/g, \"\").slice(0, 5).toUpperCase()}</big> is your verification code. if you did not request this, please ignore this email${(obj.username == null ? \". if this email was addressed to u/null instead of your Reddit username, that means your device disconnected your websocket from the setup page; voiding this verification code. to prevent this from happening, it is recommended to do the setup from a computer rather than a mobile device\" : \"\")}`).catch((err) => console.error(err));\r\n\r\n\t\tio.to(socket.id).emit(\"alert\", \"email\", \"enter the code sent to this email to verify that it's your email. check your junk/spam folder if you don't see it. the verification must be done while this page is open, so don't close this page\", \"primary\");\r\n\r\n\t\tio.to(socket.id).emit(\"enable button\", \"verify\");\r\n\t});\r\n\r\n\tsocket.on(\"verify code\", (username, code) => {\r\n\t\tif (!(username == socket.username && code == socket.id.replace(/(\\W)|(_)/g, \"\").slice(0, 5).toUpperCase())) {\r\n\t\t\tio.to(socket.id).emit(\"alert\", \"email\", \"verification failed\", \"danger\");\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tsocket.verified_email = true;\r\n\t\tio.to(socket.id).emit(\"alert\", \"email\", \"verification success\", \"success\");\r\n\t\tio.to(socket.id).emit(\"disable button\", \"verify\");\r\n\r\n\t\t(socket.firebase_service_acc_key_encrypted && socket.firebase_web_app_config_encrypted && socket.verified_email ? io.to(socket.id).emit(\"enable button\", \"save_and_continue\") : null);\r\n\t});\r\n\t\r\n\tsocket.on(\"save firebase info and email\", async () => {\r\n\t\ttry {\r\n\t\t\tawait sql.update_user(socket.username, {\r\n\t\t\t\temail_encrypted: socket.email_encrypted,\r\n\t\t\t\tfirebase_service_acc_key_encrypted: socket.firebase_service_acc_key_encrypted,\r\n\t\t\t\tfirebase_web_app_config_encrypted: socket.firebase_web_app_config_encrypted\r\n\t\t\t});\r\n\t\r\n\t\t\tio.to(socket.id).emit(\"switch page to loading\");\r\n\t\t} catch (err) {\r\n\t\t\tconsole.error(err);\r\n\t\t}\r\n\t});\r\n\r\n\tsocket.on(\"get comment from reddit\", async (comment_id) => {\r\n\t\ttry {\r\n\t\t\tconst u = await user.get(socket.username);\r\n\t\t\tconst comment_content = await u.get_comment_from_reddit(comment_id);\r\n\t\t\tio.to(socket.id).emit(\"got comment from reddit\", comment_content);\r\n\t\t} catch (err) {\r\n\t\t\tconsole.error(err);\r\n\t\t}\r\n\t});\r\n\r\n\tsocket.on(\"delete item from reddit acc\", async (item_id, item_category, item_type) => {\r\n\t\ttry {\r\n\t\t\tconst u = await user.get(socket.username);\r\n\t\t\tu.delete_item_from_reddit_acc(item_id, item_category, item_type).catch((err) => console.error(err));\r\n\t\t} catch (err) {\r\n\t\t\tconsole.error(err);\r\n\t\t}\r\n\t});\r\n\r\n\tsocket.on(\"disconnect\", () => {\r\n\t\tif (socket.username) { // logged in\r\n\t\t\t(socket.username in user.usernames_to_socket_ids ? user.usernames_to_socket_ids[socket.username] = null : null); // set to null; not delete, bc username is needed in user.update_all\r\n\t\t\tdelete user.socket_ids_to_usernames[socket.id];\t\r\n\t\t}\r\n\t});\r\n});\r\n\r\napp_socket.on(\"connect\", () => {\r\n\tconsole.log(\"connected as client to portals (localhost:1026)\");\r\n});\r\n\r\napp_socket.on(\"update domain request info\", (info) => {\r\n\tio.emit(\"update domain request info\", domain_request_info = info);\r\n});\r\n\r\napp_socket.connect();\r\n\r\nserver.listen(Number.parseInt(process.env.PORT), \"0.0.0.0\", () => {\r\n\tconsole.log(`server (eternity) started on (localhost:${process.env.PORT})`);\r\n});\r\n\r\nprocess.on(\"beforeExit\", async (exit_code) => {\r\n\ttry {\r\n\t\tawait sql.pool.end();\r\n\t} catch (err) {\r\n\t\tconsole.error(err);\r\n\t}\r\n});\r\n"
  },
  {
    "path": "backend/model/cryptr.mjs",
    "content": "import cryptr from \"cryptr\";\r\n\r\nconst cryptr_instance = new cryptr(process.env.ENCRYPTION_KEY);\r\n\r\nfunction encrypt(unencrypted_thing) { // only use it on primitives. always returns a string\r\n\tconst encrypted_thing = cryptr_instance.encrypt(unencrypted_thing);\r\n\treturn encrypted_thing;\r\n}\r\n\r\nfunction decrypt(encrypted_thing) { // takes a string and returns a string\r\n\tconst decrypted_thing = cryptr_instance.decrypt(encrypted_thing);\r\n\treturn decrypted_thing;\r\n}\r\n\r\nexport {\r\n\tencrypt,\r\n\tdecrypt\r\n};\r\n"
  },
  {
    "path": "backend/model/email.mjs",
    "content": "const backend = process.cwd();\r\n\r\nconst cryptr = await import(`${backend}/model/cryptr.mjs`);\r\n\r\nimport nodemailer from \"nodemailer\";\r\n\r\nconst transporter = nodemailer.createTransport({\r\n\tservice: \"gmail\",\r\n\tauth: {\r\n\t\ttype: \"OAuth2\",\r\n\t\tclientId: process.env.NODEMAILER_GCP_CLIENT_ID,\r\n\t\tclientSecret: process.env.NODEMAILER_GCP_CLIENT_SECRET,\r\n\t\tuser: process.env.NODEMAILER_GMAIL_ADDR,\r\n\t\trefreshToken: process.env.NODEMAILER_GMAIL_REFRESH_TOKEN\r\n\t},\r\n\tpool: true\r\n});\r\n\r\nasync function send(user, subject, msg) {\r\n\tconst info = await transporter.sendMail({\r\n\t\tfrom: '\"eternity\" <eternity@portals.sh>',\r\n\t\tto: cryptr.decrypt(user.email_encrypted),\r\n\t\tsubject: subject,\r\n\t\thtml: `\r\n\t\t\t<span>u/${user.username},</span><br/>\r\n\t\t\t<br/>\r\n\t\t\t<b>${msg}</b><br/>\r\n\t\t\t<br/>\r\n\t\t\t<br/>\r\n\t\t\t<span>—</span><br/>\r\n\t\t\t<a href=${(process.env.RUN == \"dev\" ? \"http://localhost:\" + (Number.parseInt(process.env.PORT)-1) : \"https://eternity.portals.sh\")} target=\"_blank\">eternity</a>\r\n\t\t`\r\n\t});\r\n\tconsole.log(info);\r\n}\r\n\r\nexport {\r\n\tsend\r\n};\r\n"
  },
  {
    "path": "backend/model/file.mjs",
    "content": "const backend = process.cwd();\r\n\r\nimport filesystem from \"fs\";\r\n\r\nasync function init() {\r\n\tfor (const dir of [`${backend}/logs/`, `${backend}/tempfiles/`]) {\r\n\t\tif (filesystem.existsSync(dir)) {\r\n\t\t\tif (process.env.RUN == \"dev\") {\r\n\t\t\t\tconst files = await filesystem.promises.readdir(dir);\r\n\t\t\t\tawait Promise.all(files.map((file, idx, arr) => (dir == `${backend}/logs/` ? filesystem.promises.truncate(`${dir}/${file}`.replace(\"//\", \"/\"), 0) : filesystem.promises.unlink(`${dir}/${file}`.replace(\"//\", \"/\")))));\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tfilesystem.mkdirSync(dir);\r\n\t\t}\r\n\t}\r\n}\r\n\r\nexport {\r\n\tinit\r\n};\r\n"
  },
  {
    "path": "backend/model/firebase.mjs",
    "content": "import firebase_admin from \"firebase-admin\";\r\n\r\nfunction create_app(service_acc_key, db_url, username) {\r\n\tconst app = firebase_admin.initializeApp({\r\n\t\tcredential: firebase_admin.credential.cert(service_acc_key),\r\n\t\tdatabaseURL: db_url\r\n\t}, username); // need 2nd arg (username) to be able to create multiple firebase app instances\r\n\treturn app;\r\n}\r\n\r\nasync function free_app(app) {\r\n\tawait app.delete(); // deletes instance from memory; does not actually delete anything else\r\n}\r\n\r\nfunction get_db(app) {\r\n\treturn app.database();\r\n}\r\n\r\nasync function is_empty(db) {\r\n\tconst snapshot = await db.ref().once(\"value\");\r\n\tconst db_is_empty = !snapshot.exists();\r\n\treturn db_is_empty;\r\n}\r\n\r\nasync function insert_data(db, data) {\r\n\tconst updates = {};\r\n\r\n\tfor (const category in data) {\r\n\t\tif (Object.keys(data[category].items).length > 0) {\r\n\t\t\tlet entries = Object.entries(data[category].items);\r\n\t\t\tfor (const entry of entries) {\r\n\t\t\t\tconst item_key = entry[0];\r\n\t\t\t\tconst item_value = entry[1];\r\n\r\n\t\t\t\tupdates[`${category}/items/${item_key}`] = item_value;\r\n\t\t\t}\r\n\r\n\t\t\tentries = Object.entries(data[category].item_sub_icon_urls);\r\n\t\t\tfor (const entry of entries) {\r\n\t\t\t\tconst icon_url_key = entry[0];\r\n\t\t\t\tconst icon_url_value = entry[1];\r\n\r\n\t\t\t\tupdates[`${category}/item_sub_icon_urls/${icon_url_key.replace(\"/\", \"|\").replace(\".\", \",\")}`] = icon_url_value;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\t(Object.keys(updates).length > 0 ? await db.ref().update(updates) : null);\r\n}\r\n\r\nasync function get_fns_to_import(db, category) {\r\n\tconst snapshot = await db.ref(`${category}/item_fns_to_import`).limitToFirst(500).get();\r\n\tconst data = snapshot.val(); // null if no item_fns_to_import\r\n\treturn data;\r\n}\r\n\r\nasync function delete_imported_fns(db, fns) {\r\n\tconst updates = {};\r\n\r\n\tfor (const category in fns) {\r\n\t\tif (fns[category]) {\r\n\t\t\tfor (const fn of fns[category]) {\r\n\t\t\t\tupdates[`${category}/item_fns_to_import/${fn}`] = null;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t(Object.keys(updates).length > 0 ? await db.ref().update(updates) : null);\r\n}\r\n\r\nasync function create_new_auth_token(app) {\r\n\tconst additional_claims = {\r\n\t\towner: true\r\n\t};\r\n\tconst auth_token = await app.auth().createCustomToken(app.name, additional_claims);\r\n\treturn auth_token;\r\n}\r\n\r\nexport {\r\n\tcreate_app,\r\n\tfree_app,\r\n\tget_db,\r\n\tis_empty,\r\n\tinsert_data,\r\n\tget_fns_to_import,\r\n\tdelete_imported_fns,\r\n\tcreate_new_auth_token\r\n};\r\n"
  },
  {
    "path": "backend/model/logger.mjs",
    "content": "const backend = process.cwd();\r\n\r\nimport winston from \"winston\";\r\n\r\nconst log_logger = create_logger(\"info\");\r\nconst log = log_logger.info.bind(log_logger);\r\nconst error_logger = create_logger(\"error\");\r\nconst error = error_logger.error.bind(error_logger);\r\n\r\nfunction create_logger(level) { // https://github.com/winstonjs/winston#logging-levels \"npm logging levels\"\r\n\tconst logger = winston.createLogger({\r\n\t\tformat: winston.format.combine(\r\n\t\t\twinston.format.timestamp({\r\n\t\t\t\tformat: \"YYYY-MM-DD HH:mm:ss\"\r\n\t\t\t}),\r\n\t\t\twinston.format.json(),\r\n\t\t\twinston.format.printf((log) => {\r\n\t\t\t\treturn `${JSON.stringify({\r\n\t\t\t\t\ttimestamp: log.timestamp,\r\n\t\t\t\t\tmessage: log.message\r\n\t\t\t\t}, null, 4)}`;\r\n\t\t\t})\r\n\t\t),\r\n\t\ttransports: [\r\n\t\t\t// new winston.transports.Console(),\r\n\t\t\tnew winston.transports.File({\r\n\t\t\t\tfilename: `${backend}/logs/${(level == \"info\" ? \"log\" : level)}.txt`\r\n\t\t\t})\r\n\t\t]\r\n\t});\r\n\treturn logger;\r\n}\r\n\r\nexport {\r\n\tlog,\r\n\terror\r\n};\r\n"
  },
  {
    "path": "backend/model/reddit.mjs",
    "content": "import snoowrap from \"snoowrap\";\r\n\r\nfunction create_requester(reddit_api_refresh_token) {\r\n\tconst requester = new snoowrap({\r\n\t\tclientId: process.env.REDDIT_APP_ID,\r\n\t\tclientSecret: process.env.REDDIT_APP_SECRET,\r\n\t\tuserAgent: `web:eternity${(process.env.RUN == \"dev\" ? \"_test\" : \"\")}:v=${process.env.VERSION} (by u/${process.env.REDDIT_USERNAME})`, // https://github.com/reddit-archive/reddit/wiki/API \"User-Agent\"\r\n\t\trefreshToken: reddit_api_refresh_token\r\n\t});\r\n\treturn requester;\r\n}\r\n\r\nexport {\r\n\tcreate_requester\r\n};\r\n"
  },
  {
    "path": "backend/model/sql.mjs",
    "content": "import node_pg from \"pg\";\r\nimport axios from \"axios\";\r\n\r\nconst pool = new node_pg.Pool({ // https://node-postgres.com/api/pool\r\n\tconnectionString: process.env.SQL_CONNECTION,\r\n\tmax: (process.env.RUN == \"dev\" ? 1 : 5),\r\n\tidleTimeoutMillis: 0\r\n});\r\n\r\nasync function init_db() {\r\n\tconst client = await pool.connect();\r\n\ttry {\r\n\t\tawait client.query(\"begin;\");\r\n\r\n\t\tif (process.env.RUN == \"dev\") {\r\n\t\t\tconst result = await client.query(`\r\n\t\t\t\tselect \r\n\t\t\t\t\ttable_name \r\n\t\t\t\tfrom \r\n\t\t\t\t\tinformation_schema.tables \r\n\t\t\t\twhere \r\n\t\t\t\t\ttable_schema = 'public' \r\n\t\t\t\t\tand table_type = 'BASE TABLE'\r\n\t\t\t\t;\r\n\t\t\t`);\r\n\t\t\tconst all_tables = result.rows;\r\n\t\t\tawait Promise.all(all_tables.map((table, idx, arr) => {\r\n\t\t\t\tclient.query(`\r\n\t\t\t\t\tdrop table \r\n\t\t\t\t\t\t${table.table_name} \r\n\t\t\t\t\tcascade\r\n\t\t\t\t\t;\r\n\t\t\t\t`);\r\n\t\t\t}));\r\n\t\t\tconsole.log(\"dropped all tables\");\r\n\t\t\tconsole.log(\"recreating tables\");\r\n\t\t}\r\n\t\r\n\t\tawait client.query(`\r\n\t\t\tcreate table if not exists \r\n\t\t\t\tuser_ (\r\n\t\t\t\t\tusername text primary key, \r\n\t\t\t\t\treddit_api_refresh_token_encrypted text, -- decrypt ➔ string\r\n\t\t\t\t\tcategory_sync_info json, \r\n\t\t\t\t\tlast_updated_epoch bigint, \r\n\t\t\t\t\tlast_active_epoch bigint, \r\n\t\t\t\t\temail_encrypted text, -- decrypt ➔ string\r\n\t\t\t\t\temail_notif json, \r\n\t\t\t\t\tfirebase_service_acc_key_encrypted text, -- decrypt ➔ json string\r\n\t\t\t\t\tfirebase_web_app_config_encrypted text -- decrypt ➔ json string\r\n\t\t\t\t)\r\n\t\t\t;\r\n\t\t`);\r\n\r\n\t\tawait client.query(\"commit;\");\r\n\t} catch (err) {\r\n\t\tconsole.error(err);\r\n\t\tawait client.query(\"rollback;\");\r\n\t}\r\n\tclient.release();\r\n}\r\n\r\nasync function query(query) {\r\n\tconst result = await pool.query(query);\r\n\tconst rows = (result ? result.rows : null);\r\n\treturn rows;\r\n}\r\n\r\nasync function save_user(username, reddit_api_refresh_token_encrypted, category_sync_info, last_active_epoch, email_notif) {\r\n\tawait query(`\r\n\t\tinsert into \r\n\t\t\tuser_ \r\n\t\tvalues (\r\n\t\t\t'${username}', \r\n\t\t\t'${reddit_api_refresh_token_encrypted}', \r\n\t\t\t'${JSON.stringify(category_sync_info)}', \r\n\t\t\tnull, \r\n\t\t\t${last_active_epoch}, \r\n\t\t\tnull, \r\n\t\t\t'${JSON.stringify(email_notif)}', \r\n\t\t\tnull, \r\n\t\t\tnull\r\n\t\t) \r\n\t\ton conflict (username) do -- previously purged user\r\n\t\t\tupdate \r\n\t\t\t\tset \r\n\t\t\t\t\treddit_api_refresh_token_encrypted = excluded.reddit_api_refresh_token_encrypted, \r\n\t\t\t\t\tcategory_sync_info = excluded.category_sync_info, \r\n\t\t\t\t\tlast_updated_epoch = excluded.last_updated_epoch, \r\n\t\t\t\t\tlast_active_epoch = excluded.last_active_epoch, \r\n\t\t\t\t\temail_encrypted = excluded.email_encrypted, \r\n\t\t\t\t\temail_notif = excluded.email_notif, \r\n\t\t\t\t\tfirebase_service_acc_key_encrypted = excluded.firebase_service_acc_key_encrypted, \r\n\t\t\t\t\tfirebase_web_app_config_encrypted = excluded.firebase_web_app_config_encrypted\r\n\t\t;\r\n\t`);\r\n}\r\n\r\nasync function update_user(username, fields) {\r\n\tawait query(`\r\n\t\tupdate \r\n\t\t\tuser_ \r\n\t\tset \r\n\t\t\t${Object.keys(fields).map((field, idx, arr) => `${field} = ${(typeof fields[field] == \"string\" ? \"'\" : \"\")}${fields[field]}${(typeof fields[field] == \"string\" ? \"'\" : \"\")}${(idx < arr.length-1 ? \",\" : \"\")}`).join(\" \")} \r\n\t\twhere \r\n\t\t\tusername = '${username}'\r\n\t\t;\r\n\t`);\r\n}\r\n\r\nasync function get_user(username) {\r\n\tconst rows = await query(`\r\n\t\tselect \r\n\t\t\t* \r\n\t\tfrom \r\n\t\t\tuser_ \r\n\t\twhere \r\n\t\t\tusername = '${username}'\r\n\t\t;\r\n\t`);\r\n\treturn rows[0];\r\n}\r\n\r\nasync function get_all_non_purged_users() {\r\n\tconst rows = await query(`\r\n\t\tselect \r\n\t\t\tusername \r\n\t\tfrom \r\n\t\t\tuser_ \r\n\t\twhere \r\n\t\t\treddit_api_refresh_token_encrypted is not null\r\n\t\t;\r\n\t`);\r\n\treturn rows;\r\n}\r\n\r\nasync function backup_db() {\r\n\tawait axios.post(\"https://api.elephantsql.com/api/backup\", {}, {\r\n\t\tauth: {\r\n\t\t\tusername: \"\",\r\n\t\t\tpassword: process.env.SQL_API_KEY\r\n\t\t}\r\n\t});\r\n\tconsole.log(\"backed up db\");\r\n}\r\nfunction cycle_backup_db() {\r\n\t(process.env.RUN == \"dev\" ? backup_db().catch((err) => console.error(err)) : null);\r\n\r\n\tsetInterval(() => {\r\n\t\tbackup_db().catch((err) => console.error(err));\r\n\t}, 86400000); // 24h\r\n}\r\n\r\nexport {\r\n\tpool,\r\n\tinit_db,\r\n\tsave_user,\r\n\tupdate_user,\r\n\tget_user,\r\n\tget_all_non_purged_users,\r\n\tcycle_backup_db\r\n};\r\n"
  },
  {
    "path": "backend/model/user.mjs",
    "content": "const backend = process.cwd();\r\n\r\nconst sql = await import(`${backend}/model/sql.mjs`);\r\nconst firebase = await import(`${backend}/model/firebase.mjs`);\r\nconst reddit = await import(`${backend}/model/reddit.mjs`);\r\nconst cryptr = await import(`${backend}/model/cryptr.mjs`);\r\nconst email = await import(`${backend}/model/email.mjs`);\r\nconst logger = await import(`${backend}/model/logger.mjs`);\r\nconst utils = await import(`${backend}/model/utils.mjs`);\r\n\r\nlet update_all_completed = null;\r\n\r\nconst usernames_to_socket_ids = {};\r\nconst socket_ids_to_usernames = {};\r\n\r\nclass User {\r\n\tconstructor(username, refresh_token, dummy=false) {\r\n\t\tthis.username = username;\r\n\r\n\t\tif (dummy) {\r\n\t\t\tnull;\r\n\t\t} else {\r\n\t\t\tthis.reddit_api_refresh_token_encrypted = cryptr.encrypt(refresh_token);\r\n\t\t\tthis.category_sync_info = {\r\n\t\t\t\tsaved: {\r\n\t\t\t\t\tlatest_fn_mixed: null,\r\n\t\t\t\t\tlatest_new_data_epoch: null\r\n\t\t\t\t},\r\n\t\t\t\tcreated: {\r\n\t\t\t\t\tlatest_fn_posts: null,\r\n\t\t\t\t\tlatest_fn_comments: null,\r\n\t\t\t\t\tlatest_new_data_epoch: null\r\n\t\t\t\t},\r\n\t\t\t\tupvoted: {\r\n\t\t\t\t\tlatest_fn_posts: null,\r\n\t\t\t\t\tlatest_new_data_epoch: null\r\n\t\t\t\t},\r\n\t\t\t\tdownvoted: {\r\n\t\t\t\t\tlatest_fn_posts: null,\r\n\t\t\t\t\tlatest_new_data_epoch: null\r\n\t\t\t\t},\r\n\t\t\t\thidden: {\r\n\t\t\t\t\tlatest_fn_posts: null,\r\n\t\t\t\t\tlatest_new_data_epoch: null\r\n\t\t\t\t},\r\n\t\t\t\tawarded: {\r\n\t\t\t\t\tlatest_fn_mixed: null,\r\n\t\t\t\t\tlatest_new_data_epoch: null\r\n\t\t\t\t}\r\n\t\t\t};\r\n\t\t\tthis.last_updated_epoch = null;\r\n\t\t\tthis.last_active_epoch = utils.now_epoch();\r\n\t\t\tthis.email_encrypted = null;\r\n\t\t\tthis.email_notif = {\r\n\t\t\t\tlast_inactive_notif_epoch: null,\r\n\t\t\t\tlast_update_failed_notif_epoch: null\r\n\t\t\t};\r\n\t\t\tthis.firebase_service_acc_key_encrypted = null;\r\n\t\t\tthis.firebase_web_app_config_encrypted = null;\r\n\t\t}\r\n\t}\r\n\tasync save() {\r\n\t\tlet user_for_comparison = null;\r\n\t\ttry {\r\n\t\t\tuser_for_comparison = await get(this.username, true);\r\n\t\t} catch (err) {\r\n\t\t\tif (err != `Error: user (${this.username}) dne`) {\r\n\t\t\t\tconsole.error(err);\r\n\t\t\t\tlogger.error(err);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif (!user_for_comparison || !user_for_comparison.last_updated_epoch) {\r\n\t\t\tconsole.log(`new user (${this.username})`);\r\n\r\n\t\t\tawait sql.save_user(this.username, this.reddit_api_refresh_token_encrypted, this.category_sync_info, this.last_active_epoch, this.email_notif);\r\n\t\t} else {\r\n\t\t\tconsole.log(`returning user (${this.username})`);\r\n\r\n\t\t\tawait sql.update_user(this.username, {\r\n\t\t\t\treddit_api_refresh_token_encrypted: this.reddit_api_refresh_token_encrypted\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tconsole.log(`saved user (${this.username})`);\r\n\t}\r\n\tasync get_listing(options, category, type) {\r\n\t\tlet listing = null;\r\n\t\tswitch (category) {\r\n\t\t\tcase \"saved\": // posts, comments\r\n\t\t\t\tlisting = await this.me.getSavedContent(options);\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"created\": // posts, comments\r\n\t\t\t\tswitch (type) {\r\n\t\t\t\t\tcase \"posts\":\r\n\t\t\t\t\t\tlisting = await this.me.getSubmissions(options);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase \"comments\":\r\n\t\t\t\t\t\tlisting = await this.me.getComments(options);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"upvoted\": // posts\r\n\t\t\t\tlisting = await this.me.getUpvotedContent(options);\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"downvoted\": // posts\r\n\t\t\t\tlisting = await this.me.getDownvotedContent(options);\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"hidden\": // posts\r\n\t\t\t\tlisting = await this.me.getHiddenContent(options);\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"awarded\": // posts, comments\r\n\t\t\t\tlisting = await this.me._getListing({\r\n\t\t\t\t\turi: `u/${this.username}/gilded/given`,\r\n\t\t\t\t\tqs: options\r\n\t\t\t\t});\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\treturn listing;\r\n\t}\r\n\tparse_listing(listing, category, type, from_mixed=false, from_import=false) {\r\n\t\tif (type == \"mixed\") {\r\n\t\t\t(!from_import ? this.category_sync_info[category].latest_fn_mixed = listing[0].name : null);\r\n\r\n\t\t\tconst posts = [];\r\n\t\t\tconst comments = [];\r\n\r\n\t\t\tfor (const item of listing) {\r\n\t\t\t\tswitch (item.constructor.name) {\r\n\t\t\t\t\tcase \"Submission\":\r\n\t\t\t\t\t\tposts.push(item);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase \"Comment\":\r\n\t\t\t\t\t\tcomments.push(item);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\r\n\t\t\tthis.parse_listing(posts, category, \"posts\", true);\r\n\t\t\tthis.parse_listing(comments, category, \"comments\", true);\r\n\t\t} else {\r\n\t\t\t(!from_mixed && !from_import ? this.category_sync_info[category][`latest_fn_${type}`] = listing[0].name : null);\r\n\r\n\t\t\tfor (const item of listing) {\r\n\t\t\t\tthis.new_data[category].items[item.id] = {\r\n\t\t\t\t\ttype: (type == \"posts\" ? \"post\" : \"comment\"),\r\n\t\t\t\t\tcontent: (type == \"posts\" ? item.title : item.body),\r\n\t\t\t\t\tauthor: `u/${item.author.name}`,\r\n\t\t\t\t\tsub: item.subreddit_name_prefixed,\r\n\t\t\t\t\turl: `https://www.reddit.com${utils.strip_trailing_slash(item.permalink)}`,\r\n\t\t\t\t\tcreated_epoch: item.created_utc\r\n\t\t\t\t};\r\n\r\n\t\t\t\tthis.sub_icon_urls_to_get[category].add(item.subreddit_name_prefixed);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tasync replace_latest_fn(category, type) {\r\n\t\tconst options = {\r\n\t\t\tlimit: 1\r\n\t\t};\r\n\t\tconst listing = await this.get_listing(options, category, type);\r\n\t\t\r\n\t\tconst latest_fn = (listing.length != 0 ? listing[0].name : null);\r\n\t\tthis.category_sync_info[category][`latest_fn_${type}`] = latest_fn;\r\n\t}\r\n\tasync sync_category(category, type) {\r\n\t\tlet options = {\r\n\t\t\tlimit: 5,\r\n\t\t\tbefore: this.category_sync_info[category][`latest_fn_${type}`] // \"before\" is actually chronologically after. https://www.reddit.com/dev/api/#listings\r\n\t\t};\r\n\t\tconst listing = await this.get_listing(options, category, type);\r\n\r\n\t\tif (listing.isFinished) {\r\n\t\t\tif (listing.length == 0) { // either listing actually has no items, or user deleted the latest_fn item from the listing on reddit (like, deleted it from reddit ON reddit, not deleted it from reddit on eternity)\r\n\t\t\t\tawait this.replace_latest_fn(category, type);\r\n\t\t\t} else {\r\n\t\t\t\tthis.parse_listing(listing, category, type);\r\n\t\t\t\tthis.category_sync_info[category].latest_new_data_epoch = utils.now_epoch();\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tconst extended_listing = await listing.fetchAll({\r\n\t\t\t\tappend: true\r\n\t\t\t});\r\n\t\t\tthis.parse_listing(extended_listing, category, type);\r\n\t\t\tthis.category_sync_info[category].latest_new_data_epoch = utils.now_epoch();\r\n\t\t}\r\n\t}\r\n\tasync import_category(category, type) {\r\n\t\tconst data = await firebase.get_fns_to_import(this.firebase_db, category);\r\n\t\tif (data) {\r\n\t\t\tconst fns = Object.keys(data);\r\n\r\n\t\t\tconsole.log(`importing (${fns.length}) (${category}) items`);\r\n\r\n\t\t\tconst promises = [];\r\n\r\n\t\t\tconst required_requests = Math.ceil(fns.length / 100);\r\n\t\t\tfor (let i = 0; i < required_requests; i++) {\r\n\t\t\t\tpromises.push(this.requester.getContentByIds(fns.slice(i*100, i*100 + 100))); // getContentByIds only takes max of 100 fns at once\r\n\t\t\t}\r\n\t\r\n\t\t\tconst listings = await Promise.all(promises);\r\n\t\t\tfor (const listing of listings) {\r\n\t\t\t\tthis.parse_listing(listing, category, type, false, true);\r\n\t\t\t}\r\n\r\n\t\t\tthis.category_sync_info[category].latest_new_data_epoch = utils.now_epoch();\r\n\t\r\n\t\t\tthis.imported_fns_to_delete[category] = fns;\r\n\t\t}\r\n\t}\r\n\tasync request_item_icon_urls(type, subs, category) {\r\n\t\tconst promises = [];\r\n\r\n\t\tlet required_requests = null;\r\n\t\tconst ratelimit_remaining = this.requester.ratelimitRemaining;\r\n\t\tlet i = 0;\r\n\r\n\t\tswitch (type) {\r\n\t\t\tcase \"r/\":\r\n\t\t\t\trequired_requests = Math.ceil(subs.length / 100);\r\n\t\t\t\r\n\t\t\t\tfor (; i < required_requests && i < ratelimit_remaining; i++) {\r\n\t\t\t\t\tpromises.push(this.requester.oauthRequest({\r\n\t\t\t\t\t\turi: \"api/info\", // only takes max of 100 subs at once\r\n\t\t\t\t\t\tqs: {\r\n\t\t\t\t\t\t\tsr_name: subs.slice(i*100, i*100 + 100).join(\",\")\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}));\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"u/\":\r\n\t\t\t\trequired_requests = subs.length;\r\n\r\n\t\t\t\tfor (; i < required_requests && i < ratelimit_remaining; i++) {\r\n\t\t\t\t\tpromises.push(this.requester.oauthRequest({\r\n\t\t\t\t\t\turi: `${subs[i]}/about`\r\n\t\t\t\t\t}));\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\t(i == ratelimit_remaining ? console.log(`user (${this.username}) ratelimit reached`) : null);\r\n\r\n\t\tconst responses = await Promise.all(promises);\r\n\r\n\t\tswitch (type) {\r\n\t\t\tcase \"r/\":\r\n\t\t\t\tfor (const listing of responses) {\r\n\t\t\t\t\tfor (const sub of listing) {\r\n\t\t\t\t\t\tconst sub_name = sub.display_name_prefixed;\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\tlet sub_icon_url = \"#\";\r\n\t\t\t\t\t\tif (sub.icon_img) {\r\n\t\t\t\t\t\t\tsub_icon_url = sub.icon_img.split(\"?\")[0];\r\n\t\t\t\t\t\t} else if (sub.community_icon) {\r\n\t\t\t\t\t\t\tsub_icon_url = sub.community_icon.split(\"?\")[0];\r\n\t\t\t\t\t\t}\r\n\t\t\r\n\t\t\t\t\t\tthis.new_data[category].item_sub_icon_urls[sub_name] = sub_icon_url;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"u/\":\r\n\t\t\t\tfor (const sub of responses) {\r\n\t\t\t\t\tconst sub_name = `u/${sub.name}`;\r\n\t\r\n\t\t\t\t\tlet sub_icon_url = \"#\";\r\n\t\t\t\t\tif (sub.icon_img) {\r\n\t\t\t\t\t\tsub_icon_url = sub.icon_img.split(\"?\")[0];\r\n\t\t\t\t\t} else if (sub.subreddit?.display_name.icon_img) {\r\n\t\t\t\t\t\tsub_icon_url = sub.subreddit.display_name.icon_img.split(\"?\")[0];\r\n\t\t\t\t\t} else if (sub.community_icon) {\r\n\t\t\t\t\t\tsub_icon_url = sub.community_icon.split(\"?\")[0];\r\n\t\t\t\t\t} else if (sub.subreddit?.display_name.community_icon) {\r\n\t\t\t\t\t\tsub_icon_url = sub.subreddit.display_name.community_icon.split(\"?\")[0];\r\n\t\t\t\t\t} else if (sub.snoovatar_img) {\r\n\t\t\t\t\t\tsub_icon_url = sub.snoovatar_img.split(\"?\")[0];\r\n\t\t\t\t\t} else if (sub.subreddit?.display_name.snoovatar_img) {\r\n\t\t\t\t\t\tsub_icon_url = sub.subreddit.display_name.snoovatar_img.split(\"?\")[0];\r\n\t\t\t\t\t}\r\n\t\r\n\t\t\t\t\tthis.new_data[category].item_sub_icon_urls[sub_name] = sub_icon_url;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\tasync get_new_item_icon_urls(category) {\r\n\t\tlet r_subs = []; // actual subs\r\n\t\tlet u_subs = []; // users as subs\r\n\r\n\t\tfor (const sub of this.sub_icon_urls_to_get[category]) {\r\n\t\t\tif (sub.startsWith(\"r/\")) {\r\n\t\t\t\tr_subs.push(sub);\r\n\t\t\t} else if (sub.startsWith(\"u/\")) {\r\n\t\t\t\tu_subs.push(sub);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t(r_subs.length != 0 ? await this.request_item_icon_urls(\"r/\", r_subs, category) : null);\r\n\t\t(u_subs.length != 0 ? await this.request_item_icon_urls(\"u/\", u_subs, category) : null);\r\n\t}\r\n\tasync update(io=null, socket_id=null) {\r\n\t\tconsole.log(`updating user (${this.username})`);\r\n\r\n\t\tlet progress = (io ? 0 : null);\r\n\t\tconst complete = (io ? 8 : null);\r\n\r\n\t\tthis.requester = reddit.create_requester(cryptr.decrypt(this.reddit_api_refresh_token_encrypted));\r\n\t\tthis.me = await this.requester.getMe();\r\n\r\n\t\tthis.firebase_app = firebase.create_app(JSON.parse(cryptr.decrypt(this.firebase_service_acc_key_encrypted)), JSON.parse(cryptr.decrypt(this.firebase_web_app_config_encrypted)).databaseURL, this.username);\r\n\t\tthis.firebase_db = firebase.get_db(this.firebase_app);\r\n\r\n\t\tthis.new_data = {};\r\n\t\tthis.sub_icon_urls_to_get = {};\r\n\t\tthis.imported_fns_to_delete = {};\r\n\t\t\r\n\t\tconst categories = [\"saved\", \"created\", \"upvoted\", \"downvoted\", \"hidden\", \"awarded\"];\r\n\t\tfor (const category of categories) {\r\n\t\t\tthis.new_data[category] = {\r\n\t\t\t\titems: {},\r\n\t\t\t\titem_sub_icon_urls: {}\r\n\t\t\t};\r\n\t\t\t\r\n\t\t\tthis.sub_icon_urls_to_get[category] = new Set();\r\n\t\t}\r\n\t\tcategories.pop();\r\n\t\tfor (const category of categories) {\r\n\t\t\tthis.imported_fns_to_delete[category] = null;\r\n\t\t}\r\n\r\n\t\tconst s_promise = new Promise(async (resolve, reject) => {\r\n\t\t\ttry {\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.sync_category(\"saved\", \"mixed\"));\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.import_category(\"saved\", \"mixed\"));\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.get_new_item_icon_urls(\"saved\"));\r\n\r\n\t\t\t\tif (this.firebase_app.isDeleted_) {\r\n\t\t\t\t\treject(\"firebase_app is deleted\");\r\n\t\t\t\t} else {\r\n\t\t\t\t\t(io ? io.to(socket_id).emit(\"update progress\", ++progress, complete) : null);\r\n\t\t\t\t\tresolve();\r\n\t\t\t\t}\r\n\t\t\t} catch (err) {\r\n\t\t\t\terr.extras = {\r\n\t\t\t\t\tcategory: \"saved\"\r\n\t\t\t\t};\r\n\t\t\t\treject(err);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tconst c_promise = new Promise(async (resolve, reject) => {\r\n\t\t\ttry {\r\n\t\t\t\tif (!this.firebase_app.isDeleted_) {\r\n\t\t\t\t\tawait Promise.all([\r\n\t\t\t\t\t\tthis.sync_category(\"created\", \"posts\"),\r\n\t\t\t\t\t\tthis.sync_category(\"created\", \"comments\")\r\n\t\t\t\t\t]);\r\n\t\t\t\t}\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.import_category(\"created\", \"mixed\"));\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.get_new_item_icon_urls(\"created\"));\r\n\r\n\t\t\t\tif (this.firebase_app.isDeleted_) {\r\n\t\t\t\t\treject(\"firebase_app is deleted\");\r\n\t\t\t\t} else {\r\n\t\t\t\t\t(io ? io.to(socket_id).emit(\"update progress\", ++progress, complete) : null);\r\n\t\t\t\t\tresolve();\r\n\t\t\t\t}\r\n\t\t\t} catch (err) {\r\n\t\t\t\terr.extras = {\r\n\t\t\t\t\tcategory: \"created\"\r\n\t\t\t\t};\r\n\t\t\t\treject(err);\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\t\tconst u_promise = new Promise(async (resolve, reject) => {\r\n\t\t\ttry {\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.sync_category(\"upvoted\", \"posts\"));\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.import_category(\"upvoted\", \"posts\"));\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.get_new_item_icon_urls(\"upvoted\"));\r\n\r\n\t\t\t\tif (this.firebase_app.isDeleted_) {\r\n\t\t\t\t\treject(\"firebase_app is deleted\");\r\n\t\t\t\t} else {\r\n\t\t\t\t\t(io ? io.to(socket_id).emit(\"update progress\", ++progress, complete) : null);\r\n\t\t\t\t\tresolve();\r\n\t\t\t\t}\r\n\t\t\t} catch (err) {\r\n\t\t\t\terr.extras = {\r\n\t\t\t\t\tcategory: \"upvoted\"\r\n\t\t\t\t};\r\n\t\t\t\treject(err);\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\t\tconst d_promise = new Promise(async (resolve, reject) => {\r\n\t\t\ttry {\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.sync_category(\"downvoted\", \"posts\"));\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.import_category(\"downvoted\", \"posts\"));\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.get_new_item_icon_urls(\"downvoted\"));\r\n\r\n\t\t\t\tif (this.firebase_app.isDeleted_) {\r\n\t\t\t\t\treject(\"firebase_app is deleted\");\r\n\t\t\t\t} else {\r\n\t\t\t\t\t(io ? io.to(socket_id).emit(\"update progress\", ++progress, complete) : null);\r\n\t\t\t\t\tresolve();\r\n\t\t\t\t}\r\n\t\t\t} catch (err) {\r\n\t\t\t\terr.extras = {\r\n\t\t\t\t\tcategory: \"downvoted\"\r\n\t\t\t\t};\r\n\t\t\t\treject(err);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tconst h_promise = new Promise(async (resolve, reject) => {\r\n\t\t\ttry {\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.sync_category(\"hidden\", \"posts\"));\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.import_category(\"hidden\", \"posts\"));\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.get_new_item_icon_urls(\"hidden\"));\r\n\r\n\t\t\t\tif (this.firebase_app.isDeleted_) {\r\n\t\t\t\t\treject(\"firebase_app is deleted\");\r\n\t\t\t\t} else {\r\n\t\t\t\t\t(io ? io.to(socket_id).emit(\"update progress\", ++progress, complete) : null);\r\n\t\t\t\t\tresolve();\r\n\t\t\t\t}\r\n\t\t\t} catch (err) {\r\n\t\t\t\terr.extras = {\r\n\t\t\t\t\tcategory: \"hidden\"\r\n\t\t\t\t};\r\n\t\t\t\treject(err);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tconst a_promise = new Promise(async (resolve, reject) => {\r\n\t\t\ttry {\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.sync_category(\"awarded\", \"mixed\"));\r\n\t\t\t\t(this.firebase_app.isDeleted_ ? null : await this.get_new_item_icon_urls(\"awarded\"));\r\n\r\n\t\t\t\tif (this.firebase_app.isDeleted_) {\r\n\t\t\t\t\treject(\"firebase_app is deleted\");\r\n\t\t\t\t} else {\r\n\t\t\t\t\t(io ? io.to(socket_id).emit(\"update progress\", ++progress, complete) : null);\r\n\t\t\t\t\tresolve();\r\n\t\t\t\t}\r\n\t\t\t} catch (err) {\r\n\t\t\t\terr.extras = {\r\n\t\t\t\t\tcategory: \"awarded\"\r\n\t\t\t\t};\r\n\t\t\t\treject(err);\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tawait Promise.all([s_promise, c_promise, u_promise, d_promise, h_promise, a_promise]);\r\n\r\n\t\ttry {\r\n\t\t\tawait firebase.insert_data(this.firebase_db, this.new_data);\r\n\t\t\tawait firebase.delete_imported_fns(this.firebase_db, this.imported_fns_to_delete);\r\n\t\t\tfirebase.free_app(this.firebase_app).catch((err) => console.error(err));\r\n\t\t\t(io ? io.to(socket_id).emit(\"update progress\", ++progress, complete) : null);\r\n\t\t} catch (err) {\r\n\t\t\tconsole.error(err);\r\n\t\t\tlogger.error(`user (${this.username}) db update error (${err})`);\r\n\r\n\t\t\tif (utils.now_epoch() - this.email_notif.last_update_failed_notif_epoch >= 2592000) { // 30d\r\n\t\t\t\temail.send(this, \"database update error notice\", `your database could not be updated because: ${err}. please resolve this asap`).catch((err) => console.error(err));\r\n\t\t\t\tthis.email_notif.last_update_failed_notif_epoch = utils.now_epoch();\r\n\t\t\t\tsql.update_user(this.username, {\r\n\t\t\t\t\temail_notif: JSON.stringify(this.email_notif)\r\n\t\t\t\t}).catch((err) => console.error(err));\r\n\t\t\t}\r\n\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tawait sql.update_user(this.username, {\r\n\t\t\tcategory_sync_info: JSON.stringify(this.category_sync_info),\r\n\t\t\tlast_updated_epoch: this.last_updated_epoch = utils.now_epoch()\r\n\t\t});\r\n\t\t(io ? io.to(socket_id).emit(\"update progress\", ++progress, complete) : null);\r\n\t\tconsole.log(`updated user (${this.username})`);\r\n\r\n\t\tdelete this.new_data;\r\n\t\tdelete this.sub_icon_urls_to_get;\r\n\t\tdelete this.imported_fns_to_delete;\r\n\t}\r\n\tasync get_comment_from_reddit(comment_id) {\r\n\t\tconst requester = reddit.create_requester(cryptr.decrypt(this.reddit_api_refresh_token_encrypted));\r\n\t\t\r\n\t\tconst unfetched_comment = requester.getComment(comment_id);\r\n\t\tconst fetched_comment = await unfetched_comment.fetch();\r\n\t\t\r\n\t\tconst comment_content = fetched_comment.body;\r\n\t\treturn comment_content;\r\n\t}\r\n\tasync delete_item_from_reddit_acc(item_id, item_category, item_type) {\r\n\t\tconst requester = reddit.create_requester(cryptr.decrypt(this.reddit_api_refresh_token_encrypted));\r\n\t\r\n\t\tlet item = null;\r\n\t\tlet item_fn = null; // https://www.reddit.com/dev/api/#fullnames\r\n\t\tswitch (item_type) {\r\n\t\t\tcase \"post\":\r\n\t\t\t\titem = requester.getSubmission(item_id);\r\n\t\t\t\titem_fn = `t3_${item_id}`;\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"comment\":\r\n\t\t\t\titem = requester.getComment(item_id);\r\n\t\t\t\titem_fn = `t1_${item_id}`;\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\r\n\t\tlet replace_latest_fn = null;\r\n\t\tif (item_category == \"saved\") {\r\n\t\t\treplace_latest_fn = (item_fn == this.category_sync_info.saved.latest_fn_mixed ? true : false);\r\n\t\t} else {\r\n\t\t\treplace_latest_fn = (item_fn == this.category_sync_info[item_category][`latest_fn_${item_type}s`] ? true : false);\r\n\t\t}\r\n\t\t\r\n\t\tswitch (item_category) {\r\n\t\t\tcase \"saved\":\r\n\t\t\t\tawait item.unsave();\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"created\":\r\n\t\t\t\tawait item.delete();\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"upvoted\":\r\n\t\t\tcase \"downvoted\":\r\n\t\t\t\tawait item.unvote();\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"hidden\":\r\n\t\t\t\tawait item.unhide();\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\r\n\t\tif (replace_latest_fn) {\r\n\t\t\tthis.me = await requester.getMe();\r\n\t\t\tawait this.replace_latest_fn(item_category, (item_category == \"saved\" ? \"mixed\" : `${item_type}s`));\r\n\t\t\tawait sql.update_user(this.username, {\r\n\t\t\t\tcategory_sync_info: JSON.stringify(this.category_sync_info)\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\tasync purge() {\r\n\t\tawait sql.update_user(this.username, {\r\n\t\t\treddit_api_refresh_token_encrypted: null,\r\n\t\t\tcategory_sync_info: null,\r\n\t\t\tlast_updated_epoch: null,\r\n\t\t\tlast_active_epoch: null,\r\n\t\t\temail_encrypted: null,\r\n\t\t\temail_notif: null,\r\n\t\t\tfirebase_service_acc_key_encrypted: null,\r\n\t\t\tfirebase_web_app_config_encrypted: null\r\n\t\t});\r\n\t\tdelete usernames_to_socket_ids[this.username];\r\n\t\tconsole.log(`purged user (${this.username})`);\r\n\t}\r\n}\r\n\r\nasync function fill_usernames_to_socket_ids() {\r\n\tconst rows = await sql.get_all_non_purged_users();\r\n\tfor (const row of rows) {\r\n\t\tusernames_to_socket_ids[row.username] = null;\r\n\t}\r\n}\r\n\r\nasync function get(username, existence_check=false) {\r\n\t(existence_check ? console.log(`checking if user (${username}) exists`) : console.log(`getting user (${username})`));\r\n\r\n\tconst result = await sql.get_user(username);\r\n\tif (result == undefined) {\r\n\t\tthrow new Error(`user (${username}) dne`);\r\n\t} else {\r\n\t\tconst plain_object = result;\r\n\t\t(plain_object.last_updated_epoch ? plain_object.last_updated_epoch = Number.parseInt(plain_object.last_updated_epoch) : null);\r\n\t\tplain_object.last_active_epoch = Number.parseInt(plain_object.last_active_epoch);\r\n\t\r\n\t\tconst user = Object.assign(new User(null, null, true), plain_object);\r\n\t\treturn user;\r\n\t}\r\n}\r\n\r\nasync function update_all(io) {\r\n\tconsole.log(\"update all started\");\r\n\tupdate_all_completed = false;\r\n\r\n\tconst all_usernames = Object.keys(usernames_to_socket_ids);\r\n\tfor (const username of all_usernames) {\r\n\t\tlet user = null;\r\n\t\ttry {\r\n\t\t\tuser = await get(username);\r\n\r\n\t\t\tif (user.last_updated_epoch) {\r\n\t\t\t\tif (utils.now_epoch() - user.last_active_epoch >= 15552000) { // 6mo\r\n\t\t\t\t\tif (utils.now_epoch() - user.email_notif.last_inactive_notif_epoch >= 7776000) { // 3mo\r\n\t\t\t\t\t\temail.send(user, \"account inactivity notice\", \"you have not used eternity for 6 or more consecutive months at this time. as such, your eternity account has been marked inactive and new Reddit data will not continue to sync to your database. to resolve this, log in to eternity\").catch((err) => console.error(err));\r\n\t\t\t\t\t\tuser.email_notif.last_inactive_notif_epoch = utils.now_epoch();\r\n\t\t\t\t\t\tsql.update_user(user.username, {\r\n\t\t\t\t\t\t\temail_notif: JSON.stringify(user.email_notif)\r\n\t\t\t\t\t\t}).catch((err) => console.error(err));\r\n\t\t\t\t\t}\r\n\t\t\t\t} else if (utils.now_epoch() - user.last_updated_epoch >= 30) {\r\n\t\t\t\t\tconst pre_update_category_sync_info = JSON.parse(JSON.stringify(user.category_sync_info));\r\n\r\n\t\t\t\t\tawait user.update();\r\n\t\t\t\t\t\r\n\t\t\t\t\tconst post_update_category_sync_info = user.category_sync_info;\r\n\t\t\t\t\t\r\n\t\t\t\t\tconst socket_id = usernames_to_socket_ids[user.username];\r\n\t\t\t\t\tif (socket_id) {\r\n\t\t\t\t\t\tconst categories_w_new_data = [];\r\n\t\t\t\t\t\tfor (const category in user.category_sync_info) {\r\n\t\t\t\t\t\t\t(post_update_category_sync_info[category].latest_new_data_epoch > pre_update_category_sync_info[category].latest_new_data_epoch ? categories_w_new_data.push(category) : null);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\t(categories_w_new_data.length > 0 ? io.to(socket_id).emit(\"show refresh alert\", categories_w_new_data) : null);\r\n\r\n\t\t\t\t\t\tio.to(socket_id).emit(\"store last updated epoch\", user.last_updated_epoch);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t} catch (err) {\r\n\t\t\tif (err != `Error: user (${username}) dne`) {\r\n\t\t\t\tconsole.error(err);\r\n\t\t\t\tlogger.error(`user (${username}) update error (${err})`);\r\n\r\n\t\t\t\t(user.firebase_app ? firebase.free_app(user.firebase_app).catch((err) => console.error(err)) : null);\r\n\r\n\t\t\t\tif (err.statusCode == 403 && err.options.qs.before) {\r\n\t\t\t\t\ttry {\r\n\t\t\t\t\t\tswitch (err.extras.category) {\r\n\t\t\t\t\t\t\tcase \"saved\":\r\n\t\t\t\t\t\t\tcase \"awarded\":\r\n\t\t\t\t\t\t\t\tawait user.replace_latest_fn(err.extras.category, \"mixed\");\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tcase \"created\":\r\n\t\t\t\t\t\t\t\tawait Promise.all([\r\n\t\t\t\t\t\t\t\t\tuser.replace_latest_fn(err.extras.category, \"posts\"),\r\n\t\t\t\t\t\t\t\t\tuser.replace_latest_fn(err.extras.category, \"comments\")\r\n\t\t\t\t\t\t\t\t]);\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tcase \"upvoted\":\r\n\t\t\t\t\t\t\tcase \"downvoted\":\r\n\t\t\t\t\t\t\tcase \"hidden\":\r\n\t\t\t\t\t\t\t\tawait user.replace_latest_fn(err.extras.category, \"posts\");\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\tdefault:\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tawait sql.update_user(user.username, {\r\n\t\t\t\t\t\t\tcategory_sync_info: JSON.stringify(user.category_sync_info)\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t} catch (err) {\r\n\t\t\t\t\t\tconsole.error(err);\r\n\t\t\t\t\t\tlogger.error(`user (${username}) replace_latest_fn error (${err})`);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n\r\n\tupdate_all_completed = true;\r\n\tconsole.log(\"update all completed\");\r\n}\r\nfunction cycle_update_all(io) {\r\n\tupdate_all(io).catch((err) => console.error(err));\r\n\r\n\tsetInterval(() => {\r\n\t\t(update_all_completed ? update_all(io).catch((err) => console.error(err)) : null);\r\n\t}, 60000); // 1min\r\n}\r\n\r\nexport {\r\n\tUser,\r\n\tusernames_to_socket_ids,\r\n\tsocket_ids_to_usernames,\r\n\tfill_usernames_to_socket_ids,\r\n\tget,\r\n\tcycle_update_all\r\n};\r\n"
  },
  {
    "path": "backend/model/utils.mjs",
    "content": "function now_epoch() {\r\n\tconst now_epoch = Math.floor(Date.now() / 1000);\r\n\treturn now_epoch;\r\n}\r\n\r\nfunction strip_trailing_slash(string) {\r\n\tconst stripped_string = (string.endsWith(\"/\") ? string.slice(0, -1) : string);\r\n\treturn stripped_string;\r\n}\r\n\r\nexport {\r\n\tnow_epoch,\r\n\tstrip_trailing_slash\r\n};\r\n"
  },
  {
    "path": "backend/nodemon.json",
    "content": "{\r\n\t\"ext\": \"mjs\"\r\n}\r\n"
  },
  {
    "path": "backend/package.json",
    "content": "{\r\n\t\"type\": \"module\",\r\n\t\"scripts\": {\r\n\t\t\"dev\": \"RUN=dev PORT=1301 nodemon ./controller/server.mjs\",\r\n\t\t\"prod_start\": \"RUN=prod PORT=1301 pm2 start ./controller/server.mjs --interpreter node --name eternity --update-env\",\r\n\t\t\"prod_stop\": \"pm2 stop ./controller/server.mjs\"\r\n\t},\r\n\t\"devDependencies\": {\r\n\t\t\"@types/node\": \"18.11.9\",\r\n\t\t\"nodemon\": \"2.0.20\"\r\n\t},\r\n\t\"dependencies\": {\r\n\t\t\"axios\": \"0.26.1\",\r\n\t\t\"cookie-session\": \"1.4.0\",\r\n\t\t\"cryptr\": \"6.0.3\",\r\n\t\t\"dotenv\": \"16.0.3\",\r\n\t\t\"express\": \"4.18.2\",\r\n\t\t\"express-fileupload\": \"1.4.0\",\r\n\t\t\"firebase-admin\": \"10.3.0\",\r\n\t\t\"internal-ip\": \"7.0.0\",\r\n\t\t\"nodemailer\": \"6.8.0\",\r\n\t\t\"passport\": \"0.5.3\",\r\n\t\t\"passport-reddit\": \"0.2.4\",\r\n\t\t\"pg\": \"8.8.0\",\r\n\t\t\"snoowrap\": \"1.23.0\",\r\n\t\t\"socket.io\": \"4.5.3\",\r\n\t\t\"socket.io-client\": \"4.5.3\",\r\n\t\t\"winston\": \"3.8.2\"\r\n\t}\r\n}\r\n"
  },
  {
    "path": "frontend/.npmrc",
    "content": "engine-strict=true\r\nunsafe-perm=true\r\nsave-exact=true\r\n"
  },
  {
    "path": "frontend/package.json",
    "content": "{\r\n\t\"type\": \"module\",\r\n\t\"scripts\": {\r\n\t\t\"dev\": \"RUN=dev PORT=1300 vite dev\",\r\n\t\t\"build\": \"vite build\",\r\n\t\t\"preview\": \"vite preview\"\r\n\t},\r\n\t\"devDependencies\": {\r\n\t\t\"@sveltejs/adapter-static\": \"1.0.0-next.39\",\r\n\t\t\"@sveltejs/kit\": \"1.0.0-next.405\",\r\n\t\t\"svelte\": \"3.49.0\",\r\n\t\t\"vite\": \"3.0.7\"\r\n\t},\r\n\t\"dependencies\": {\r\n\t\t\"axios\": \"0.26.1\",\r\n\t\t\"firebase\": \"8.10.1\",\r\n\t\t\"socket.io-client\": \"4.5.3\",\r\n\t\t\"underscore\": \"1.13.6\",\r\n\t\t\"xlsx\": \"0.18.5\"\r\n\t}\r\n}\r\n"
  },
  {
    "path": "frontend/source/app.html",
    "content": "<!DOCTYPE html>\n<html>\n\t<head>\n\t\t%sveltekit.head%\n\t\t<meta charset=\"utf-8\"/>\n\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>\n\t\t<link rel=\"icon\" type=\"image/png\" href=\"/favicon.png\"/>\n\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css\" integrity=\"sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\"/>\n\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.18/css/bootstrap-select.min.css\" integrity=\"sha512-ARJR74swou2y0Q2V9k0GbzQ/5vJ2RBSoCWokg4zkfM29Fb3vZEQyv0iWBMW/yvKgyHSR/7D64pFMmU8nYmbRkg==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\"/>\n\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css\" integrity=\"sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\"/>\n\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdnjs.cloudflare.com/ajax/libs/three-dots/0.2.1/three-dots.min.css\" integrity=\"sha512-dWmVYu6HOa5uQf4SwTAGU1i0G9oOEDKX2+8ZOcown+l6dmFstrnv2ucyCnuVs3XmSIZzz976nGNNNg/CIska0A==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\"/>\n\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"/style.css\"/>\n\t\t<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js\" integrity=\"sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\" defer></script>\n\t\t<script src=\"https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\" defer></script>\n\t\t<script src=\"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.18/js/bootstrap-select.min.js\" integrity=\"sha512-yDlE7vpGDP7o2eftkCiPZ+yuUyEcaBwoJoIhdXv71KZWugFqEphIS3PU60lEkFaz8RxaVsMpSvQxMBaKVwA5xg==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\" defer></script>\n\t\t<script src=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/js/all.min.js\" integrity=\"sha512-RXf+QSDCUQs5uwRKaDoXt55jygZZm2V++WUZduaU/Ui/9EGp3f/2KZVahFZBKGH0s774sd3HmrhUy+SgOFQLVQ==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\" defer></script>\n\t\t<noscript><span class=\"text-light\">this web app requires JavaScript to run. enable JavaScript to continue!</span></noscript>\n\t</head>\n\t<body>\n\t\t%sveltekit.body%\n\t</body>\n</html>\n"
  },
  {
    "path": "frontend/source/components/access.svelte",
    "content": "<script context=\"module\">\r\n\timport * as globals from \"frontend/source/globals.js\";\r\n\timport * as utils from \"frontend/source/utils.js\";\r\n\timport Navbar from \"frontend/source/components/navbar.svelte\";\r\n\r\n\timport * as svelte from \"svelte\";\r\n\timport axios from \"axios\";\r\n\timport underscore from \"underscore\";\r\n\r\n\tconst globals_r = globals.readonly;\r\n\tconst globals_w = globals.writable;\r\n</script>\r\n<script>\r\n\texport let username;\r\n\t\r\n\tlet [\r\n\t\tlast_updated_epoch,\r\n\t\tlast_updated_wrappers_update_interval_id,\r\n\t\tlast_updated_wrapper_1,\r\n\t\tlast_updated_wrapper_2,\r\n\t\tsearch_input,\r\n\t\tsearch_btn,\r\n\t\tsubreddit_select,\r\n\t\tsubreddit_select_btn,\r\n\t\tsubreddit_select_dropdown,\r\n\t\tcategory_btn_group,\r\n\t\ttype_btn_group,\r\n\t\titem_list,\r\n\t\tskeleton_list,\r\n\t\tnew_data_alert_wrapper\r\n\t] = [];\r\n\r\n\tlet active_data = { // entire active_category data\r\n\t\titems: new Map(),\r\n\t\titem_sub_icon_urls: {}\r\n\t};\r\n\tlet active_category = \"saved\";\r\n\tlet active_type = \"all\";\r\n\tlet active_sub = \"all\";\r\n\tlet active_search_str = \"\";\r\n\tlet active_item_ids = []; // ids of filtered items (by selected type, subreddit, and search string). only these items will be listed in item_list from active_data\r\n\tlet items_currently_listed = 0;\r\n\r\n\tconst intersection_observer = new IntersectionObserver((entries) => {\r\n\t\tfor (const entry of entries) {\r\n\t\t\tif (entry.intersectionRatio > 0) { // observed element is in view\r\n\t\t\t\tintersection_observer.unobserve(entry.target);\r\n\t\t\t\tlist_next_items(25);\r\n\t\t\t}\r\n\t\t}\r\n\t}, {\r\n\t\troot: document,\r\n\t\trootMargin: \"0px\",\r\n\t\tthreshold: 0\r\n\t});\r\n\r\n\tconst debounced_hide_popover = underscore.debounce(() => {\r\n\t\tjQuery(\"[data-toggle='popover']\").popover(\"hide\");\r\n\t}, 100, true);\r\n\r\n\tasync function handle_body_click(evt) {\r\n\t\t(evt.target.classList.contains(\"dropdown-item\") || evt.target.parentElement?.classList.contains(\"dropdown-item\") ? subreddit_select_btn.blur() : null);\r\n\r\n\t\tif (evt.target.dataset?.url) {\r\n\t\t\twindow.open(evt.target.dataset.url, \"_blank\");\r\n\t\t} else if (evt.target.parentElement?.dataset?.url && evt.target.tagName != \"BUTTON\") {\r\n\t\t\twindow.open(evt.target.parentElement.dataset.url, \"_blank\");\r\n\t\t}\r\n\r\n\t\tif (evt.target.classList.contains(\"copy_link_btn\") || evt.target.classList.contains(\"text_btn\") || evt.target.classList.contains(\"renew_btn\")) {\r\n\t\t\tevt.target.classList.remove(\"btn-outline-secondary\");\r\n\t\t\tevt.target.classList.add(\"btn-success\");\r\n\t\t\tsetTimeout(() => {\r\n\t\t\t\tevt.target.classList.remove(\"btn-success\");\r\n\t\t\t\tevt.target.classList.add(\"btn-outline-secondary\");\r\n\t\t\t}, 500);\r\n\r\n\t\t\tif (evt.target.classList.contains(\"copy_link_btn\")) {\r\n\t\t\t\twindow.navigator.clipboard.writeText(evt.target.parentElement.dataset.url).catch((err) => console.error(err));\r\n\t\t\t} else if (evt.target.classList.contains(\"text_btn\")) {\r\n\t\t\t\tconst post_text_wrapper = evt.target.parentElement.querySelector(\".post_text_wrapper\");\r\n\t\t\t\tif (post_text_wrapper.innerHTML == \"\") {\r\n\t\t\t\t\ttry {\r\n\t\t\t\t\t\tconst post_id = evt.target.parentElement.id;\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\tconst response = await axios.get(`https://api.pushshift.io/reddit/search/submission?ids=${post_id}&fields=selftext`);\r\n\t\t\t\t\t\tconst response_data = response.data;\r\n\r\n\t\t\t\t\t\tconst post_text = response_data.data[0].selftext;\r\n\t\t\t\t\t\tpost_text_wrapper.innerHTML = (post_text ? underscore.escape(post_text) : \"[this is not a text post]\");\r\n\t\t\t\t\t} catch (err) {\r\n\t\t\t\t\t\tconsole.error(err);\r\n\t\t\t\t\t\tpost_text_wrapper.innerHTML = \"[error: pushshift currently down. please try again later]\";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tpost_text_wrapper.classList.toggle(\"d-none\");\r\n\t\t\t} else if (evt.target.classList.contains(\"renew_btn\")) {\r\n\t\t\t\tconst comment_id = evt.target.parentElement.id;\r\n\r\n\t\t\t\tglobals_r.socket.emit(\"get comment from reddit\", comment_id);\r\n\t\t\t\tglobals_r.socket.once(\"got comment from reddit\", (comment_content) => {\r\n\t\t\t\t\tconst content_wrapper = evt.target.parentElement.querySelector(\".content_wrapper\");\r\n\t\t\t\t\tcontent_wrapper.innerHTML = underscore.escape(comment_content);\r\n\r\n\t\t\t\t\t$globals_w.firebase_db.ref(`${active_category}/items/${comment_id}/content`).set(comment_content).catch((err) => console.error(err));\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif (evt.target.classList.contains(\"delete_btn\")) {\r\n\t\t\tconst item_id = evt.target.parentElement.id;\r\n\r\n\t\t\tconst all_opened_popovers = document.querySelectorAll(\".popover\");\r\n\t\t\tfor (const popover of all_opened_popovers) {\r\n\t\t\t\tconst popover_item_id = popover.children[2].children[0].classList[0];\r\n\t\t\t\t\r\n\t\t\t\t(popover_item_id != item_id ? jQuery(popover).popover(\"hide\") : null);\r\n\t\t\t}\r\n\t\t} else if (evt.target.classList.contains(\"row_1_popover_btn\")) {\r\n\t\t\tconst all_row_1_popover_btns = document.querySelectorAll(\".row_1_popover_btn\");\r\n\t\t\tfor (const btn of all_row_1_popover_btns) {\r\n\t\t\t\tif (btn != evt.target) {\r\n\t\t\t\t\tbtn.classList.remove(\"active\");\r\n\t\t\t\t} else {\r\n\t\t\t\t\tbtn.classList.toggle(\"active\");\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t} else if (evt.target.classList.contains(\"delete_item_confirm_btn\")) {\r\n\t\t\tconst opened_popover = document.querySelector(\".popover\");\r\n\r\n\t\t\tlet delete_from = null;\r\n\t\t\tconst all_row_1_popover_btns = document.querySelectorAll(\".row_1_popover_btn\");\r\n\t\t\tfor (const btn of all_row_1_popover_btns) {\r\n\t\t\t\t(btn.classList.contains(\"active\") ? delete_from = btn.innerHTML : null);\r\n\t\t\t}\r\n\t\t\tif (!delete_from) {\r\n\t\t\t\tfor (const btn of [...all_row_1_popover_btns]) {\r\n\t\t\t\t\tutils.shake_element(btn);\r\n\t\t\t\t}\r\n\t\t\t\treturn;\r\n\t\t\t} else {\r\n\t\t\t\tjQuery(opened_popover).popover(\"hide\");\r\n\t\t\t}\r\n\r\n\t\t\tconst item_id = evt.target.parentElement.parentElement.classList[0];\r\n\t\t\tconst item_category = active_category;\r\n\t\t\tconst item_type = document.querySelector(`[id=\"${item_id}\"]`).dataset.type;\r\n\r\n\t\t\tif (delete_from == \"eternity\" || delete_from == \"both\") {\r\n\t\t\t\tconst list_item = document.querySelector(`[id=\"${item_id}\"]`);\r\n\t\t\t\tlist_item.innerHTML = \"\";\r\n\t\t\t\tlist_item.removeAttribute(\"data-url\");\r\n\t\t\t\tlist_item.removeAttribute(\"data-type\");\r\n\t\t\t\tlist_item.className = \"\";\r\n\t\t\t\tlist_item.classList.add(\"skeleton_item\", \"rounded\", \"mb-2\");\r\n\r\n\t\t\t\ttry {\r\n\t\t\t\t\tawait $globals_w.firebase_db.ref(`${item_category}/items/${item_id}`).remove();\r\n\t\r\n\t\t\t\t\tlist_item.remove();\r\n\t\t\t\t\tactive_item_ids.splice(active_item_ids.indexOf(item_id), 1);\r\n\t\t\t\t\tactive_data.items.delete(item_id);\r\n\t\t\t\t} catch (err) {\r\n\t\t\t\t\tconsole.error(err);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (delete_from == \"Reddit\" || delete_from == \"both\") {\r\n\t\t\t\tglobals_r.socket.emit(\"delete item from reddit acc\", item_id, item_category, item_type);\r\n\t\t\t}\r\n\t\t} else if (!evt.target.classList.contains(\"row_2_popover_btn\") && document.querySelector(\".popover\")?.contains(evt.target)) {\r\n\t\t\tnull;\r\n\t\t} else {\r\n\t\t\tjQuery(\"[data-toggle='popover']\").popover(\"hide\");\r\n\t\t}\r\n\r\n\t\tif (evt.target.parentElement == category_btn_group) {\r\n\t\t\tconst selected_category = await new Promise((resolve, reject) => {\r\n\t\t\t\tsetTimeout(() => {\r\n\t\t\t\t\tlet category = null;\r\n\t\t\t\t\tfor (const btn of [...(category_btn_group.children)]) {\r\n\t\t\t\t\t\t(btn.classList.contains(\"active\") ? category = btn.innerText : null);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tresolve(category);\r\n\t\t\t\t}, 100);\r\n\t\t\t});\r\n\t\t\tif (selected_category != active_category) {\r\n\t\t\t\tactive_category = selected_category;\r\n\t\t\t\tshow_skeleton_loading();\r\n\t\t\t\ttry {\r\n\t\t\t\t\tawait get_parse_set_active_data();\r\n\t\t\t\t} catch (err) {\r\n\t\t\t\t\tconsole.error(err);\r\n\t\t\t\t}\r\n\t\t\t\trefresh_item_list();\r\n\t\t\t\thide_skeleton_loading();\r\n\t\t\t\tupdate_search_placeholder();\r\n\t\t\t\tfill_subreddit_select();\r\n\t\t\t}\r\n\t\t} else if (evt.target.parentElement == type_btn_group) {\r\n\t\t\tconst selected_type = await new Promise((resolve, reject) => {\r\n\t\t\t\tsetTimeout(() => {\r\n\t\t\t\t\tlet type = null;\r\n\t\t\t\t\tfor (const btn of [...(type_btn_group.children)]) {\r\n\t\t\t\t\t\t(btn.classList.contains(\"active\") ? type = btn.innerText : null);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tresolve(type);\r\n\t\t\t\t}, 100);\r\n\t\t\t});\r\n\t\t\tif (selected_type != active_type) {\r\n\t\t\t\tactive_type = selected_type;\r\n\t\t\t\trefresh_item_list();\r\n\t\t\t\tupdate_search_placeholder();\r\n\t\t\t\tfill_subreddit_select();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (evt.target.id == \"refresh_btn\") {\r\n\t\t\tnew_data_alert_wrapper.classList.add(\"d-none\");\r\n\t\t\tshow_skeleton_loading();\r\n\t\t\ttry {\r\n\t\t\t\tawait get_parse_set_active_data();\r\n\t\t\t} catch (err) {\r\n\t\t\t\tconsole.error(err);\r\n\t\t\t}\r\n\t\t\trefresh_item_list();\r\n\t\t\thide_skeleton_loading();\r\n\t\t\tupdate_search_placeholder();\r\n\t\t\tfill_subreddit_select();\r\n\t\t}\r\n\t}\r\n\r\n\tfunction handle_body_keydown(evt) {\r\n\t\tif (evt.key == \"Escape\") {\r\n\t\t\tjQuery(\"[data-toggle='popover']\").popover(\"hide\");\r\n\t\t}\r\n\t\t\r\n\t\tsetTimeout(() => {\r\n\t\t\tconst no_results = document.querySelector(\".no-results\");\r\n\t\t\t(no_results && !no_results.classList.contains(\"d-none\") ? no_results.classList.add(\"d-none\") : null);\r\n\r\n\t\t\t(subreddit_select_dropdown && typeof subreddit_select_dropdown != \"number\" && !subreddit_select_dropdown.classList.contains(\"show\") ? subreddit_select_btn.blur() : null);\r\n\t\t}, 100);\r\n\t}\r\n\r\n\tasync function get_parse_set_active_data() {\r\n\t\tactive_data.items.clear();\r\n\t\tactive_data.item_sub_icon_urls = {};\r\n\r\n\t\tconst snapshot = await $globals_w.firebase_db.ref(active_category).get();\r\n\t\tconst data = snapshot.val();\r\n\t\tif (data) {\r\n\t\t\tif (data.items) {\r\n\t\t\t\tconst sorted_items_entries = Object.entries(data.items).sort((a, b) => b[1].created_epoch - a[1].created_epoch); // sort by created_epoch, descending\r\n\t\t\t\tfor (const entry of sorted_items_entries) {\r\n\t\t\t\t\tconst item_key = entry[0];\r\n\t\t\t\t\tconst item_value = entry[1];\r\n\t\t\t\r\n\t\t\t\t\tactive_data.items.set(item_key, item_value);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (data.item_sub_icon_urls) {\r\n\t\t\t\tconst icon_urls_entries = Object.entries(data.item_sub_icon_urls);\r\n\t\t\t\tfor (const entry of icon_urls_entries) {\r\n\t\t\t\t\tconst icon_url_key = entry[0];\r\n\t\t\t\t\tconst icon_url_value = entry[1];\r\n\r\n\t\t\t\t\tactive_data.item_sub_icon_urls[icon_url_key.replace(\"|\", \"/\").replace(\",\", \".\")] = icon_url_value;\r\n\t\t\t\t}\r\n\t\t\t}\t\r\n\t\t}\r\n\t}\r\n\r\n\tfunction show_skeleton_loading() {\r\n\t\titem_list.scrollTop = 0;\r\n\t\titem_list.classList.add(\"d-none\");\r\n\t\tskeleton_list.classList.remove(\"d-none\");\r\n\t}\r\n\r\n\tfunction hide_skeleton_loading() {\r\n\t\tskeleton_list.classList.add(\"d-none\");\r\n\t\titem_list.classList.remove(\"d-none\");\r\n\t\titem_list.scrollTop = 0;\r\n\t}\r\n\r\n\tfunction set_active_item_ids() { // filter ➔ set\r\n\t\t// filter by selected type\r\n\t\tswitch (active_type) {\r\n\t\t\tcase \"all\":\r\n\t\t\t\tactive_item_ids = [...(active_data.items.keys())];\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"posts\":\r\n\t\t\tcase \"comments\":\r\n\t\t\t\tactive_item_ids = [];\r\n\t\t\t\tfor (const entry of active_data.items) {\r\n\t\t\t\t\tconst item_key = entry[0];\r\n\t\t\t\t\tconst item_value = entry[1];\r\n\r\n\t\t\t\t\t(item_value.type == active_type.slice(0, -1) ? active_item_ids.push(item_key) : null);\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\r\n\t\t// filter by selected subreddit\r\n\t\tif (active_sub != \"all\") {\r\n\t\t\tconst filtered_items = new Map();\r\n\t\t\tfor (const item_id of active_item_ids) {\r\n\t\t\t\tfiltered_items.set(item_id, active_data.items.get(item_id));\r\n\t\t\t}\r\n\t\t\r\n\t\t\tactive_item_ids = [];\r\n\t\t\tfor (const entry of filtered_items) {\r\n\t\t\t\tconst item_key = entry[0];\r\n\t\t\t\tconst item_value = entry[1];\r\n\r\n\t\t\t\t(item_value.sub == active_sub ? active_item_ids.push(item_key) : null);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// filter by search string\r\n\t\tif (active_search_str != \"\") {\r\n\t\t\tconst space_delimited_search_input = active_search_str.split(\" \").map((term, idx, arr) => term.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")); // escape regex special chars: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\r\n\r\n\t\t\tconst filtered_items = new Map();\r\n\t\t\tfor (const item_id of active_item_ids) {\r\n\t\t\t\tfiltered_items.set(item_id, active_data.items.get(item_id));\r\n\t\t\t}\r\n\t\t\r\n\t\t\tactive_item_ids = [];\r\n\t\t\tfor (const entry of filtered_items) {\r\n\t\t\t\tconst item_key = entry[0];\r\n\t\t\t\tconst item_value = entry[1];\r\n\r\n\t\t\t\tlet matches = 0;\r\n\t\t\t\tfor (const term of space_delimited_search_input) {\r\n\t\t\t\t\tconst re = new RegExp(term, \"i\");\r\n\t\t\t\t\t(re.test(item_value.sub) || re.test(item_value.author) || re.test(item_value.content) ? matches++ : null);\r\n\t\t\t\t}\r\n\t\t\t\t(matches == space_delimited_search_input.length ? active_item_ids.push(item_key) : null);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction list_next_items(count) {\r\n\t\tif (active_type == \"comments\" && (active_category == \"upvoted\" || active_category == \"downvoted\" || active_category == \"hidden\")) {\r\n\t\t\titem_list.innerHTML = `<div class=\"list-group-item text-light lead\">${active_category} comment data not provided by Reddit api</div>`;\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tconst max_items = active_item_ids.length;\r\n\t\tif (max_items == 0) {\t\t\r\n\t\t\titem_list.innerHTML = '<div class=\"list-group-item text-light lead\">no results</div>';\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tconst x = items_currently_listed + count;\r\n\t\twhile (items_currently_listed < x && items_currently_listed < max_items) {\r\n\t\t\tconst item_id = active_item_ids[items_currently_listed];\r\n\t\t\tconst item = active_data.items.get(item_id);\r\n\r\n\t\t\titem_list.insertAdjacentHTML(\"beforeend\", `\r\n\t\t\t\t<div id=\"${item_id}\" class=\"list-group-item list-group-item-action text-left text-light p-1\" data-url=\"${item.url}\" data-type=\"${item.type}\">\r\n\t\t\t\t\t<a href=\"https://www.reddit.com/${item.sub}\" target=\"_blank\"><img src=\"${active_data.item_sub_icon_urls[item.sub]}\" class=\"rounded-circle${(active_data.item_sub_icon_urls[item.sub] == \"#\" ? \"\" : \" border border-light\")}\"/></a><small><a href=\"https://www.reddit.com/${item.sub}\" target=\"_blank\"><b class=\"ml-2\">${item.sub}</b></a> &bull; <a href=\"https://www.reddit.com/${item.author}\" target=\"_blank\">${item.author}</a> &bull; <i data-url=\"${item.url}\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"${utils.epoch_to_formatted_datetime(item.created_epoch)}\">${utils.time_since(item.created_epoch)}</i></small>\r\n\t\t\t\t\t<p class=\"lead line_height_1 m-0\" data-url=\"${item.url}\"><${(item.type == \"post\" ? \"b\" : \"small\")} class=\"content_wrapper noto_sans\">${underscore.escape(item.content)}</${(item.type == \"post\" ? \"b\" : \"small\")}></p>\r\n\t\t\t\t\t<button type=\"button\" class=\"delete_btn btn btn-sm btn-outline-secondary shadow-none border-0 py-0\" data-toggle=\"popover\" data-placement=\"right\" data-title=\"delete item from\" data-content='<div class=\"${item_id}\"><div><span class=\"row_1_popover_btn btn btn-sm btn-primary float-left px-0\">eternity</span><span class=\"row_1_popover_btn btn btn-sm btn-primary float-center px-0\">Reddit</span><span class=\"row_1_popover_btn btn btn-sm btn-primary float-right px-0\">both</span></div><div><span class=\"row_2_popover_btn btn btn-sm btn-secondary float-left mt-2\">cancel</span><span class=\"row_2_popover_btn delete_item_confirm_btn btn btn-sm btn-danger float-right mt-2\">confirm</span></div><div class=\"clearfix\"></div></div>' data-html=\"true\">delete</button> <button type=\"button\" class=\"copy_link_btn btn btn-sm btn-outline-secondary shadow-none border-0 py-0\">copy link</button> <button type=\"button\" class=\"${(item.type == \"post\" ? \"text\" : \"renew\")}_btn btn btn-sm btn-outline-secondary shadow-none border-0 py-0\">${(item.type == \"post\" ? \"text\" : \"renew\")}</button>\r\n\t\t\t\t\t${(item.type == \"post\" ? '<p class=\"post_text_wrapper noto_sans line_height_1 d-none m-0\"></p>' : \"\")}\r\n\t\t\t\t</div>\r\n\t\t\t`);\r\n\r\n\t\t\t(++items_currently_listed == x-Math.floor(count/2)-1 ? intersection_observer.observe(document.querySelector(`[id=\"${item_id}\"]`)) : null);\r\n\r\n\t\t\tjQuery('[data-toggle=\"tooltip\"]').tooltip(\"enable\");\r\n\t\t\tjQuery('[data-toggle=\"popover\"]').popover(\"enable\");\r\n\t\t}\r\n\t}\r\n\r\n\tfunction refresh_item_list() {\r\n\t\tintersection_observer.disconnect(); // stops observing all currently observed elements. (does NOT stop the intersection observer. i.e., it can still observe new elements)\r\n\t\titem_list.innerHTML = \"\";\r\n\t\titem_list.scrollTop = 0;\r\n\t\titems_currently_listed = 0;\r\n\r\n\t\tset_active_item_ids();\r\n\t\tlist_next_items(25);\r\n\t}\r\n\r\n\tfunction update_search_placeholder() {\r\n\t\tconst item_count = active_item_ids.length;\r\n\t\tsearch_input.placeholder = `search ${item_count} item${(item_count == 1 ? \"\" : \"s\")}`;\r\n\t}\r\n\r\n\tfunction fill_subreddit_select() {\r\n\t\tsubreddit_select.innerHTML = \"<option>all</option>\";\r\n\r\n\t\tlet subs = new Set();\r\n\t\tif (active_type == \"all\") {\r\n\t\t\tfor (const entry of active_data.items) {\r\n\t\t\t\tconst item_key = entry[0];\r\n\t\t\t\tconst item_value = entry[1];\r\n\r\n\t\t\t\tsubs.add(item_value.sub);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tfor (const entry of active_data.items) {\r\n\t\t\t\tconst item_key = entry[0];\r\n\t\t\t\tconst item_value = entry[1];\r\n\r\n\t\t\t\t(item_value.type == active_type.slice(0, -1) ? subs.add(item_value.sub) : null);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tsubs = [...subs];\r\n\t\tsubs.sort((a, b) => a.localeCompare(b, \"en\"));\r\n\r\n\t\tfor (const sub of subs) {\r\n\t\t\tsubreddit_select.insertAdjacentHTML(\"beforeend\", `\r\n\t\t\t\t<option>${sub}</option>\r\n\t\t\t`);\r\n\t\t}\r\n\t\tjQuery(subreddit_select).selectpicker(\"refresh\");\r\n\t\tjQuery(subreddit_select).selectpicker(\"render\");\r\n\t}\r\n\r\n\tsvelte.onMount(async () => {\r\n\t\tglobals_r.socket.emit(\"page\", \"access\");\r\n\t\t\r\n\t\tglobals_r.socket.on(\"store last updated epoch\", (epoch) => {\r\n\t\t\tlast_updated_epoch = epoch;\r\n\t\t});\r\n\r\n\t\tglobals_r.socket.on(\"show refresh alert\", (categories_w_new_data) => {\r\n\t\t\tfor (const category of categories_w_new_data) {\r\n\t\t\t\tif (category == active_category) {\r\n\t\t\t\t\tnew_data_alert_wrapper.classList.remove(\"d-none\");\r\n\t\t\t\t\tutils.show_alert(new_data_alert_wrapper, '<span class=\"ml-1\">new data available!</span><button id=\"refresh_btn\" class=\"btn btn-sm btn-primary ml-2\">refresh</button>', \"primary\");\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tlast_updated_wrappers_update_interval_id = setInterval(() => {\r\n\t\t\tif (last_updated_epoch) {\r\n\t\t\t\tlast_updated_wrapper_1.innerHTML = utils.time_since(last_updated_epoch);\r\n\t\t\t\tlast_updated_wrapper_2.innerHTML = utils.epoch_to_formatted_datetime(last_updated_epoch);\r\n\t\t\t}\r\n\t\t}, 1000);\r\n\r\n\t\ttry {\r\n\t\t\tawait new Promise((resolve, reject) => {\r\n\t\t\t\tconst interval_id = setInterval(() => {\r\n\t\t\t\t\tif ($globals_w.firebase_app && $globals_w.firebase_auth && $globals_w.firebase_db) {\r\n\t\t\t\t\t\tclearInterval(interval_id);\r\n\t\t\t\t\t\tresolve();\r\n\t\t\t\t\t}\r\n\t\t\t\t}, 100);\r\n\t\t\t});\r\n\r\n\t\t\tawait get_parse_set_active_data();\r\n\t\t\trefresh_item_list();\r\n\t\t\thide_skeleton_loading();\r\n\t\t\tupdate_search_placeholder();\r\n\t\t\tfill_subreddit_select();\r\n\t\t} catch (err) {\r\n\t\t\tconsole.error(err);\r\n\t\t}\r\n\r\n\t\tjQuery(subreddit_select).selectpicker();\r\n\t\tsubreddit_select_btn = document.querySelector(\".bs-placeholder\");\r\n\t\tsubreddit_select_dropdown = document.querySelector(\".bootstrap-select\");\r\n\r\n\t\tjQuery(subreddit_select).on(\"changed.bs.select\", (evt, clicked_idx, is_selected, previous_value) => { // https://developer.snapappointments.com/bootstrap-select/options/#events\r\n\t\t\tactive_sub = evt.target.value;\r\n\t\t\trefresh_item_list();\r\n\t\t\tupdate_search_placeholder();\r\n\t\t});\r\n\r\n\t\tlast_updated_wrapper_1.addEventListener(\"click\", (evt) => {\r\n\t\t\tlast_updated_wrapper_2.classList.toggle(\"d-none\");\r\n\t\t});\r\n\r\n\t\tlast_updated_wrapper_2.addEventListener(\"click\", (evt) => {\r\n\t\t\tevt.target.classList.toggle(\"d-none\");\r\n\t\t});\r\n\r\n\t\tsubreddit_select_btn.addEventListener(\"click\", (evt) => {\r\n\t\t\t(!subreddit_select_dropdown.classList.contains(\"show\") ? subreddit_select_btn.blur() : null);\r\n\t\t});\r\n\r\n\t\tsearch_input.addEventListener(\"keydown\", (evt) => {\r\n\t\t\tif (evt.target.value.trim() == \"\") {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tswitch (evt.key) {\r\n\t\t\t\tcase \"Enter\":\r\n\t\t\t\t\tactive_search_str = evt.target.value.trim();\r\n\t\t\t\t\trefresh_item_list();\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"Escape\":\r\n\t\t\t\t\tevt.target.value = \"\";\r\n\t\t\t\t\tactive_search_str = \"\";\r\n\t\t\t\t\trefresh_item_list();\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"Backspace\":\r\n\t\t\t\tcase \"Delete\":\r\n\t\t\t\t\tsetTimeout(() => {\r\n\t\t\t\t\t\tif (active_search_str && evt.target.value.trim() == \"\") {\r\n\t\t\t\t\t\t\tactive_search_str = \"\";\r\n\t\t\t\t\t\t\trefresh_item_list();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}, 100);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tsearch_btn.addEventListener(\"click\", (evt) => {\r\n\t\t\tsearch_input.dispatchEvent(new KeyboardEvent(\"keydown\", {\r\n\t\t\t\tkey: \"Enter\"\r\n\t\t\t}));\r\n\t\t});\r\n\r\n\t\titem_list.addEventListener(\"scroll\", (evt) => {\r\n\t\t\tdebounced_hide_popover();\r\n\t\t});\r\n\t});\r\n\tsvelte.onDestroy(() => {\r\n\t\tglobals_r.socket.off(\"store last updated epoch\");\r\n\t\tglobals_r.socket.off(\"show refresh alert\");\r\n\r\n\t\tclearInterval(last_updated_wrappers_update_interval_id);\r\n\t});\r\n</script>\r\n\r\n<svelte:body on:click={handle_body_click} on:keydown={handle_body_keydown}/>\r\n<Navbar username={username} show_data_anchors={true}/>\r\n<div class=\"text-center mt-3\">\r\n\t<h1 class=\"display-4\">{globals_r.app_name}</h1>\r\n\t<span>last updated: <b bind:this={last_updated_wrapper_1} id=\"last_updated_wrapper_1\">?</b> ago</span>\r\n\t<br/>\r\n\t<small bind:this={last_updated_wrapper_2} class=\"d-none\">?</small>\r\n\t<div class=\"d-flex justify-content-center\">\r\n\t\t<div bind:this={new_data_alert_wrapper} class=\"px-1 d-none\"></div>\r\n\t</div>\r\n\t<div id=\"access_container\" class=\"card card-body bg-dark mt-3 pb-3\">\r\n\t\t<form>\r\n\t\t\t<div class=\"form-row d-flex justify-content-center\">\r\n\t\t\t\t<div bind:this={category_btn_group} class=\"btn-group btn-group-toggle flex-wrap\" data-toggle=\"buttons\">\r\n\t\t\t\t\t<label class=\"btn btn-secondary shadow-none active\"><input type=\"radio\" name=\"options\"/>saved</label>\r\n\t\t\t\t\t<label class=\"btn btn-secondary shadow-none\"><input type=\"radio\" name=\"options\"/>created</label>\r\n\t\t\t\t\t<label class=\"btn btn-secondary shadow-none\"><input type=\"radio\" name=\"options\"/>upvoted</label>\r\n\t\t\t\t\t<label class=\"btn btn-secondary shadow-none\"><input type=\"radio\" name=\"options\"/>downvoted</label>\r\n\t\t\t\t\t<label class=\"btn btn-secondary shadow-none\"><input type=\"radio\" name=\"options\"/>hidden</label>\r\n\t\t\t\t</div>\r\n\t\t\t</div>\r\n\t\t\t<div class=\"form-row d-flex justify-content-center mt-2\">\r\n\t\t\t\t<div bind:this={type_btn_group} class=\"btn-group btn-group-toggle flex-wrap\" data-toggle=\"buttons\">\r\n\t\t\t\t\t<label class=\"btn btn-secondary shadow-none\"><input type=\"radio\" name=\"options\"/>posts</label>\r\n\t\t\t\t\t<label class=\"btn btn-secondary shadow-none\"><input type=\"radio\" name=\"options\"/>comments</label>\r\n\t\t\t\t\t<label class=\"btn btn-secondary shadow-none active\"><input type=\"radio\" name=\"options\"/>all</label>\r\n\t\t\t\t</div>\r\n\t\t\t</div>\r\n\t\t\t<div class=\"form-row mt-2\">\r\n\t\t\t\t<div class=\"form-group col-12 col-sm-8 mb-0\">\r\n\t\t\t\t\t<div class=\"d-flex input-group\">\r\n\t\t\t\t\t\t<input bind:this={search_input} type=\"text\" class=\"form-control bg-light\" placeholder=\"search ? items\"/>\r\n\t\t\t\t\t\t<div class=\"input-group-append\"><button bind:this={search_btn} type=\"button\" class=\"btn btn-light shadow-none\"><i class=\"fa fa-search\"></i></button></div>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t<div class=\"form-group col-12 col-sm-4 mb-0\">\r\n\t\t\t\t\t<select bind:this={subreddit_select} class=\"selectpicker form-control\" data-width=\"false\" data-size=\"10\" data-live-search=\"true\" title=\"in subreddit: all\">\r\n\t\t\t\t\t\t<option>all</option>\r\n\t\t\t\t\t</select>\r\n\t\t\t\t</div>\r\n\t\t\t</div>\r\n\t\t</form>\r\n\t</div>\r\n\t<div class=\"card card-body bg-dark border-top-0 mt-n2 pt-0 pb-2 pr-2\">\r\n\t\t<div bind:this={item_list} class=\"list-group list-group-flush border-0 d-none\" id=\"item_list\"></div>\r\n\t\t<div bind:this={skeleton_list} class=\"list-group\" id=\"skeleton_list\">\r\n\t\t\t{#each {length: 7} as _, idx}\r\n\t\t\t\t<div class=\"skeleton_item rounded mb-2\"></div>\r\n\t\t\t{/each}\r\n\t\t</div>\r\n\t</div>\r\n</div>\r\n"
  },
  {
    "path": "frontend/source/components/footer.svelte",
    "content": "<script context=\"module\">\r\n\timport * as globals from \"frontend/source/globals.js\";\r\n\r\n\timport * as svelte from \"svelte\";\r\n\r\n\tconst globals_r = globals.readonly;\r\n</script>\r\n<script>\r\n\tlet [\r\n\t\tdropdown_btn,\r\n\t\tdropdown_menu,\r\n\t\tlast24hours_total_wrapper,\r\n\t\tlast7days_total_wrapper,\r\n\t\tlast30days_total_wrapper,\r\n\t\tlast24hours_list_wrapper,\r\n\t\tlast7days_list_wrapper,\r\n\t\tlast30days_list_wrapper\r\n\t] = [];\r\n\r\n\tfunction handle_body_keydown(evt) {\r\n\t\tif (evt.key == \"Escape\") {\r\n\t\t\tsetTimeout(() => {\r\n\t\t\t\t(!dropdown_menu.classList.contains(\"show\") ? dropdown_btn.blur() : null);\r\n\t\t\t}, 100);\r\n\t\t}\r\n\t}\r\n\r\n\tfunction list_domain_request_info(countries, parent_ul) {\r\n\t\tparent_ul.innerHTML = \"\";\r\n\t\t\r\n\t\tif (countries.length == 0) {\r\n\t\t\treturn;\r\n\t\t} else if (countries.length <= 3) {\r\n\t\t\tfor (const country of countries) {\r\n\t\t\t\tparent_ul.insertAdjacentHTML(\"beforeend\", `\r\n\t\t\t\t\t<li class=\"mt-n1\">${country.clientCountryName}: ${country.requests}</li>\r\n\t\t\t\t`);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tfor (const country of countries.slice(0, 3)) {\r\n\t\t\t\tparent_ul.insertAdjacentHTML(\"beforeend\", `\r\n\t\t\t\t\t<li class=\"mt-n1\">${country.clientCountryName}: ${country.requests}</li>\r\n\t\t\t\t`);\r\n\t\t\t}\r\n\r\n\t\t\tparent_ul.insertAdjacentHTML(\"beforeend\", `\r\n\t\t\t\t<li class=\"mt-n1\">${countries.length - 3} more</li>\r\n\t\t\t`);\r\n\t\t}\r\n\t}\r\n\r\n\tsvelte.onMount(() => {\r\n\t\tglobals_r.socket.on(\"update domain request info\", (domain_request_info) => {\r\n\t\t\tif (!domain_request_info || Object.keys(domain_request_info).length == 0) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tlast24hours_total_wrapper.innerHTML = domain_request_info.last24hours_total;\r\n\t\t\tlast7days_total_wrapper.innerHTML = domain_request_info.last7days_total;\r\n\t\t\tlast30days_total_wrapper.innerHTML = domain_request_info.last30days_total;\r\n\r\n\t\t\tlist_domain_request_info(domain_request_info.last24hours_countries, last24hours_list_wrapper);\r\n\t\t\tlist_domain_request_info(domain_request_info.last7days_countries, last7days_list_wrapper);\r\n\t\t\tlist_domain_request_info(domain_request_info.last30days_countries, last30days_list_wrapper);\r\n\t\t});\r\n\r\n\t\tdropdown_btn.addEventListener(\"click\", (evt) => {\r\n\t\t\tsetTimeout(() => {\r\n\t\t\t\t(!dropdown_menu.classList.contains(\"show\") ? dropdown_btn.blur() : null);\r\n\t\t\t}, 100);\r\n\r\n\t\t\tsetTimeout(() => {\r\n\t\t\t\tdropdown_menu.scrollIntoView({\r\n\t\t\t\t\tbehavior: \"smooth\",\r\n\t\t\t\t\tblock: \"end\"\r\n\t\t\t\t});\r\n\t\t\t}, 250);\r\n\t\t});\r\n\t});\r\n\tsvelte.onDestroy(() => {\r\n\t\tglobals_r.socket.off(\"update domain request info\");\r\n\t});\r\n</script>\r\n\r\n<svelte:body on:keydown={handle_body_keydown}/>\r\n<footer class=\"text-center\">\r\n\t<p class=\"font_size_10 m-0\"><a href=\"/about\">about</a></p>\r\n\t<p class=\"font_size_10 m-0\"><a href=\"https://github.com/sponsors/jc9108\" target=\"_blank\">support this project</a></p>\r\n\t<p class=\"font_size_10 m-0\">released under the <a href=\"https://choosealicense.com/licenses/agpl-3.0\" target=\"_blank\">AGPL3 License</a> &#169; <a href={globals_r.portals} target=\"_blank\">portals</a></p>\r\n\t<p class=\"font_size_10 m-0\"><a href={`${globals_r.portals}/stats`} target=\"_blank\">cloudflare zone stats</a></p>\r\n\t<div class=\"btn-group dropdown\">\r\n\t\t<button bind:this={dropdown_btn} type=\"button\" class=\"btn btn-link dropdown-toggle mt-n2 px-1 py-0\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\" data-display=\"static\"></button>\r\n\t\t<div bind:this={dropdown_menu} class=\"dropdown-menu rounded-0 bg-light mt-n2 px-2 py-0\" id=\"dropdown_menu\">\r\n\t\t\t<p class=\"text-center m-0\"><b>domain requests</b></p>\r\n\t\t\t<div class=\"dropdown-divider m-0\"></div>\r\n\t\t\t<span>last 24 hours: <span bind:this={last24hours_total_wrapper}></span></span>\r\n\t\t\t<ul bind:this={last24hours_list_wrapper} class=\"m-0\"></ul>\r\n\t\t\t<div class=\"dropdown-divider m-0\"></div>\r\n\t\t\t<span>last 7 days: <span bind:this={last7days_total_wrapper}></span></span>\r\n\t\t\t<ul bind:this={last7days_list_wrapper} class=\"m-0\"></ul>\r\n\t\t\t<div class=\"dropdown-divider m-0\"></div>\r\n\t\t\t<span>last 30 days: <span bind:this={last30days_total_wrapper}></span></span>\r\n\t\t\t<ul bind:this={last30days_list_wrapper} class=\"m-0\"></ul>\r\n\t\t\t<div class=\"dropdown-divider m-0\"></div>\r\n\t\t\t<div class=\"text-center mt-n1\">\r\n\t\t\t\t<a class=\"font_size_10\" href={`${globals_r.portals}/stats`} target=\"_blank\">full details</a>\r\n\t\t\t</div>\r\n\t\t</div>\r\n\t</div>\r\n</footer>\r\n"
  },
  {
    "path": "frontend/source/components/landing.svelte",
    "content": "<script context=\"module\">\r\n\timport * as globals from \"frontend/source/globals.js\";\r\n\timport Navbar from \"frontend/source/components/navbar.svelte\";\r\n\r\n\timport * as svelte from \"svelte\";\r\n\r\n\tconst globals_r = globals.readonly;\r\n</script>\r\n<script>\r\n\tsvelte.onMount(() => {\r\n\t\tglobals_r.socket.emit(\"page\", \"landing\");\r\n\t});\r\n</script>\r\n\r\n<Navbar/>\r\n<div class=\"text-center mt-3\">\r\n\t<div class=\"jumbotron bg-dark mb-0 py-5\">\r\n\t\t<h1 class=\"display-4\">{globals_r.app_name}</h1>\r\n\t\t<p class=\"lead text-left\">{globals_r.description}</p>\r\n\t\t<p class=\"lead text-left\">features: new items auto-sync, synced items not affected by Reddit deletion, search for items, filter by subreddit, import csv data from <a href=\"https://www.reddit.com/settings/data-request\" target=\"_blank\">Reddit data request</a>, export data as json</p>\r\n\t\t<hr class=\"bg-secondary my-4\"/>\r\n\t\t<div class=\"embed-responsive embed-responsive-16by9\">\r\n\t\t\t<iframe title=\"demo\" class=\"embed-responsive-item\" src=\"https://www.youtube.com/embed/4pxXM98ewIc\" allow=\"fullscreen\"></iframe>\r\n\t\t</div>\r\n\t\t<hr class=\"bg-secondary my-4\"/>\r\n\t\t<p class=\"lead text-left\">required <a href=\"https://www.reddit.com/dev/api/oauth\" target=\"_blank\">Reddit api oauth2 scopes</a>::</p>\r\n\t\t<ul class=\"text-left mt-n3\">\r\n\t\t\t<li><a href=\"https://www.reddit.com/dev/api/oauth#scope_identity\" target=\"_blank\">identity</a>: to get your username</li>\r\n\t\t\t<li><a href=\"https://www.reddit.com/dev/api/oauth#scope_history\" target=\"_blank\">history</a>: to get your items</li>\r\n\t\t\t<li><a href=\"https://www.reddit.com/dev/api/oauth#scope_read\" target=\"_blank\">read</a>: to get icons of subreddits/users</li>\r\n\t\t\t<li><a href=\"https://www.reddit.com/dev/api/oauth#scope_save\" target=\"_blank\">save</a>: to unsave items (manual action)</li>\r\n\t\t\t<li><a href=\"https://www.reddit.com/dev/api/oauth#scope_edit\" target=\"_blank\">edit</a>: to delete items (manual action)</li>\r\n\t\t\t<li><a href=\"https://www.reddit.com/dev/api/oauth#scope_vote\" target=\"_blank\">vote</a>: to unvote items (manual action)</li>\r\n\t\t\t<li><a href=\"https://www.reddit.com/dev/api/oauth#scope_report\" target=\"_blank\">report</a>: to unhide items (manual action)</li>\r\n\t\t</ul>\r\n\t\t<div class=\"row\">\r\n\t\t\t<div class=\"col-1 col-sm-3\"></div>\r\n\t\t\t<div class=\"col-10 col-sm-6\">\r\n\t\t\t\t<a id=\"login_anchor\" class=\"d-flex justify-content-center\" href=\"{globals_r.backend}/login\" rel=\"external\"><p class=\"rounded-pill lead text-white mt-2\" id=\"login_btn\">log in with <img id=\"reddit_logo\" class=\"ml-n2 mr-n2 mb-1\" src=\"/reddit logo on dark.svg\" alt=\"reddit logo\"/></p></a>\r\n\t\t\t</div>\r\n\t\t\t<div class=\"col-1 col-sm-3\"></div>\r\n\t\t</div>\r\n\t</div>\r\n</div>\r\n"
  },
  {
    "path": "frontend/source/components/loading.svelte",
    "content": "<script context=\"module\">\r\n\timport * as globals from \"frontend/source/globals.js\";\r\n\timport Navbar from \"frontend/source/components/navbar.svelte\";\r\n\r\n\timport * as svelte from \"svelte\";\r\n\r\n\tconst globals_r = globals.readonly;\r\n</script>\r\n<script>\r\n\texport let username;\r\n\t\r\n\tlet progress_wrapper = null;\r\n\r\n\tconst dispatch = svelte.createEventDispatcher();\r\n\r\n\tsvelte.onMount(() => {\r\n\t\tglobals_r.socket.emit(\"page\", \"loading\");\r\n\r\n\t\tglobals_r.socket.on(\"update progress\", (progress, complete) => {\r\n\t\t\tconst progress_percentage = progress/complete * 100;\r\n\t\t\tprogress_wrapper.innerHTML = Math.floor(progress_percentage);\r\n\t\t\tif (progress_percentage == 100) {\r\n\t\t\t\tsetTimeout(() => {\r\n\t\t\t\t\tdispatch(\"dispatch\", \"switch page to access\");\r\n\t\t\t\t}, 2000);\r\n\t\t\t}\r\n\t\t});\r\n\t});\r\n\tsvelte.onDestroy(() => {\r\n\t\tglobals_r.socket.off(\"update progress\");\r\n\t});\r\n</script>\r\n\r\n<Navbar username={username}/>\r\n<div class=\"text-center mt-3 mb-4\">\r\n\t<h1 class=\"display-4\">{globals_r.app_name}</h1>\r\n\t<div id=\"loading_container\" class=\"mt-1\">\r\n\t\t<div class=\"spinner-border\" role=\"status\"><span class=\"sr-only\">loading...</span></div>\r\n\t\t<p class=\"mt-n5\"><span bind:this={progress_wrapper} class=\"lead\">?</span>%</p>\r\n\t</div>\r\n</div>\r\n"
  },
  {
    "path": "frontend/source/components/navbar.svelte",
    "content": "<script context=\"module\">\r\n\timport * as globals from \"frontend/source/globals.js\";\r\n\timport * as utils from \"frontend/source/utils.js\";\r\n\r\n\timport * as svelte from \"svelte\";\r\n\timport * as xlsx from \"xlsx\";\r\n\r\n\tconst globals_r = globals.readonly;\r\n\tconst globals_w = globals.writable;\r\n</script>\r\n<script>\r\n\texport let username;\r\n\texport let show_data_anchors;\r\n\texport let show_return_to_app;\r\n\r\n\tlet [\r\n\t\tsettings_btn,\r\n\t\tsettings_menu,\r\n\t\timport_anchor,\r\n\t\timport_notice,\r\n\t\tfiles_input,\r\n\t\tselected_files_list,\r\n\t\timport_cancel_btn,\r\n\t\timport_confirm_btn,\r\n\t\texport_anchor,\r\n\t\tnew_tab_json,\r\n\t\tpurge_anchor,\r\n\t\tpurge_warning,\r\n\t\tpurge_input,\r\n\t\tpurge_cancel_btn,\r\n\t\tpurge_confirm_btn,\r\n\t\tpurge_spinner_container,\r\n\t\tredirect_notice,\r\n\t\tredirect_countdown_wrapper,\r\n\t\tmodal\r\n\t] = [];\r\n\r\n\tfunction toggle_import_notice() {\r\n\t\treset_import_notice();\r\n\t\timport_notice.classList.toggle(\"d-none\");\r\n\t}\r\n\r\n\tfunction hide_import_notice() {\r\n\t\treset_import_notice();\r\n\t\t(!import_notice.classList.contains(\"d-none\") ? import_notice.classList.add(\"d-none\") : null);\r\n\t}\r\n\r\n\tfunction reset_import_notice() {\r\n\t\tfiles_input.files = new DataTransfer().files;\r\n\t\tselected_files_list.innerHTML = \"\";\r\n\t}\r\n\r\n\tfunction toggle_purge_warning() {\r\n\t\tpurge_input.value = \"\";\r\n\t\tpurge_warning.classList.toggle(\"d-none\");\r\n\t}\r\n\r\n\tfunction hide_purge_warning() {\r\n\t\tpurge_input.value = \"\";\r\n\t\t(!purge_warning.classList.contains(\"d-none\") ? purge_warning.classList.add(\"d-none\") : null);\r\n\t}\r\n\r\n\tasync function purge() {\r\n\t\ttoggle_purge_warning();\r\n\t\tpurge_spinner_container.classList.toggle(\"d-none\");\r\n\r\n\t\ttry {\r\n\t\t\tconst response = await fetch(`${globals_r.backend}/purge?&socket_id=${globals_r.socket.id}`, {\r\n\t\t\t\tmethod: \"get\"\r\n\t\t\t});\r\n\t\t\tconst response_data = await response.text();\r\n\r\n\t\t\tif (response_data == \"success\") {\r\n\t\t\t\tsetTimeout(() => {\r\n\t\t\t\t\twindow.location.reload();\r\n\t\t\t\t}, 10000);\r\n\t\t\t\t\r\n\t\t\t\tpurge_spinner_container.classList.toggle(\"d-none\");\r\n\t\t\t\tredirect_notice.classList.toggle(\"d-none\");\r\n\r\n\t\t\t\tlet countdown = 10;\r\n\t\t\t\tsetInterval(() => {\r\n\t\t\t\t\tredirect_countdown_wrapper.innerHTML = --countdown;\r\n\t\t\t\t}, 1000);\r\n\t\t\t} else {\r\n\t\t\t\tconsole.error(response_data);\r\n\t\t\t}\r\n\t\t} catch (err) {\r\n\t\t\tconsole.error(err);\r\n\t\t}\r\n\t}\r\n\r\n\tsvelte.onMount(() => {\r\n\t\tif (!username) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tsettings_btn.addEventListener(\"click\", (evt) => {\r\n\t\t\tsetTimeout(() => {\r\n\t\t\t\tif (!settings_menu.classList.contains(\"show\")) {\r\n\t\t\t\t\tsettings_btn.blur();\r\n\t\t\t\t\thide_purge_warning();\r\n\t\t\t\t\t(show_data_anchors ? hide_import_notice() : null);\r\n\t\t\t\t}\r\n\t\t\t}, 100);\r\n\t\t});\r\n\r\n\t\tsettings_menu.addEventListener(\"click\", (evt) => {\r\n\t\t\tevt.stopPropagation();\r\n\t\t});\r\n\r\n\t\tpurge_anchor.addEventListener(\"click\", (evt) => {\r\n\t\t\tevt.preventDefault();\r\n\t\t\ttoggle_purge_warning();\r\n\t\t\t(show_data_anchors ? hide_import_notice() : null);\r\n\t\t});\r\n\r\n\t\tpurge_cancel_btn.addEventListener(\"click\", (evt) => {\r\n\t\t\tevt.preventDefault();\r\n\t\t\ttoggle_purge_warning();\r\n\t\t});\r\n\r\n\t\tpurge_confirm_btn.addEventListener(\"click\", (evt) => {\r\n\t\t\tevt.preventDefault();\r\n\t\t\t(purge_input.value == `purge u/${username}` ? purge() : utils.shake_element(purge_input));\r\n\t\t});\r\n\r\n\t\tpurge_input.addEventListener(\"keydown\", (evt) => {\r\n\t\t\tif (evt.key == \"Enter\") {\r\n\t\t\t\tevt.preventDefault();\r\n\t\t\t\t(purge_input.value == `purge u/${username}` ? purge() : utils.shake_element(purge_input));\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tif (!show_data_anchors) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\timport_anchor.addEventListener(\"click\", (evt) => {\r\n\t\t\tevt.preventDefault();\r\n\t\t\thide_purge_warning();\r\n\t\t\ttoggle_import_notice();\r\n\t\t});\r\n\r\n\t\timport_cancel_btn.addEventListener(\"click\", (evt) => {\r\n\t\t\tevt.preventDefault();\r\n\t\t\ttoggle_import_notice();\r\n\t\t});\r\n\r\n\t\timport_confirm_btn.addEventListener(\"click\", async (evt) => {\r\n\t\t\tevt.preventDefault();\r\n\r\n\t\t\tselected_files_list.innerHTML = \"\";\r\n\t\t\tif (files_input.files.length == 0) {\r\n\t\t\t\tselected_files_list.insertAdjacentHTML(\"beforeend\", `\r\n\t\t\t\t\t<li class=\"mb-1\"><b class=\"text-danger\">NO FILE(S) SELECTED</b></li>\r\n\t\t\t\t`);\r\n\t\t\t\treturn;\r\n\t\t\t} else {\r\n\t\t\t\tselected_files_list.insertAdjacentHTML(\"beforeend\", `\r\n\t\t\t\t\t<li class=\"mb-1\"><b class=\"text-danger\">PREPARING IMPORT. DO NOT CLOSE THIS PAGE UNTIL IT'S READY. YOU WILL KNOW WHEN YOU SEE A MODAL (POPUP)</b></li>\r\n\t\t\t\t`);\r\n\t\t\t}\r\n\r\n\t\t\tconst item_fns = {};\r\n\r\n\t\t\tconst categories = [\"saved\", \"created\", \"upvoted\", \"downvoted\", \"hidden\"];\r\n\t\t\tfor (const category of categories) {\r\n\t\t\t\titem_fns[category] = [];\r\n\t\t\t}\r\n\r\n\t\t\tfor (const file_idx in ((({length, ...rest}) => rest)(files_input.files))) {\r\n\t\t\t\tconst file = files_input.files[file_idx];\r\n\r\n\t\t\t\tconst csv = await new Promise((resolve, reject) => {\r\n\t\t\t\t\tconst reader = new FileReader();\r\n\t\t\t\t\treader.readAsBinaryString(file);\r\n\t\t\t\t\treader.onloadend = function (evt) {\r\n\t\t\t\t\t\tresolve(xlsx.read(evt.target.result, {\r\n\t\t\t\t\t\t\ttype: \"binary\"\r\n\t\t\t\t\t\t}));\r\n\t\t\t\t\t}\r\n\t\t\t\t\treader.onerror = function (evt) {\r\n\t\t\t\t\t\treject(reader.error);\r\n\t\t\t\t\t}\r\n\t\t\t\t});\r\n\t\t\t\tconst sheet_list = csv.SheetNames;\r\n\t\t\t\tconst sheet = csv.Sheets[sheet_list[0]];\r\n\t\t\t\tconst items = xlsx.utils.sheet_to_json(sheet);\r\n\r\n\t\t\t\tswitch (file.name) {\r\n\t\t\t\t\tcase \"saved_posts.csv\":\r\n\t\t\t\t\t\titem_fns.saved.push(...(items.map((item, idx, arr) => `t3_${item.id}`)));\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase \"saved_comments.csv\":\r\n\t\t\t\t\t\titem_fns.saved.push(...(items.map((item, idx, arr) => `t1_${item.id}`)));\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase \"posts.csv\":\r\n\t\t\t\t\t\titem_fns.created.push(...(items.map((item, idx, arr) => `t3_${item.id}`)));\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase \"comments.csv\":\r\n\t\t\t\t\t\titem_fns.created.push(...(items.map((item, idx, arr) => `t1_${item.id}`)));\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase \"post_votes.csv\":\r\n\t\t\t\t\t\tfor (const item of items) {\r\n\t\t\t\t\t\t\t(item.direction == \"none\" ? null : item_fns[`${item.direction}voted`].push(`t3_${item.id}`));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase \"hidden_posts.csv\":\r\n\t\t\t\t\t\titem_fns.hidden = items.map((item, idx, arr) => `t3_${item.id}`);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tconst updates = {};\r\n\t\t\tfor (const category in item_fns) {\r\n\t\t\t\tif (item_fns[category].length > 0) {\r\n\t\t\t\t\tfor (const fn of item_fns[category]) {\r\n\t\t\t\t\t\t(fn.includes(\".\") ? null : updates[`${category}/item_fns_to_import/${fn}`] = fn); // exclude anomaly fns: see thread https://www.reddit.com/r/help/comments/rztejh/saved_posts_beyond_the_1000_visible_limit\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tawait $globals_w.firebase_db.ref().update(updates);\r\n\r\n\t\t\tjQuery(modal).modal(\"show\");\r\n\t\t});\r\n\r\n\t\tfiles_input.addEventListener(\"input\", (evt) => {\r\n\t\t\tselected_files_list.innerHTML = \"\";\r\n\r\n\t\t\tfor (let i = 0; i < files_input.files.length; i++) {\r\n\t\t\t\tconst file = files_input.files[i];\r\n\t\t\t\tconst filename = file.name;\r\n\t\t\t\tconst filesize = file.size; // in binary bytes\r\n\t\t\t\tconst filesize_limit = 10485760; // 10mb in binary bytes\r\n\r\n\t\t\t\tswitch (filename) {\r\n\t\t\t\t\tcase \"saved_posts.csv\":\r\n\t\t\t\t\tcase \"saved_comments.csv\":\r\n\t\t\t\t\tcase \"posts.csv\":\r\n\t\t\t\t\tcase \"comments.csv\":\r\n\t\t\t\t\tcase \"post_votes.csv\":\r\n\t\t\t\t\tcase \"hidden_posts.csv\":\r\n\t\t\t\t\t\tselected_files_list.insertAdjacentHTML(\"beforeend\", `\r\n\t\t\t\t\t\t\t<li class=\"mb-1\"><b><code class=\"text-dark\">${filename}</code></b></li>\r\n\t\t\t\t\t\t`);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\treset_import_notice();\r\n\t\t\t\t\t\tselected_files_list.insertAdjacentHTML(\"beforeend\", `\r\n\t\t\t\t\t\t\t<li class=\"mb-1\"><b class=\"text-danger\">UNALLOWED FILE SELECTED. PLEASE TRY AGAIN</b></li>\r\n\t\t\t\t\t\t`);\r\n\t\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (filesize > filesize_limit) {\r\n\t\t\t\t\treset_import_notice();\r\n\t\t\t\t\tselected_files_list.insertAdjacentHTML(\"beforeend\", `\r\n\t\t\t\t\t\t<li class=\"mb-1\"><b class=\"text-danger\">PER-FILE SIZE LIMIT IS 10mb</b></li>\r\n\t\t\t\t\t`);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\texport_anchor.addEventListener(\"click\", async (evt) => {\r\n\t\t\tevt.preventDefault();\r\n\t\t\t\r\n\t\t\ttry {\r\n\t\t\t\tconst id_token = await $globals_w.firebase_auth.currentUser.getIdToken();\r\n\t\t\t\tnew_tab_json.href = `${$globals_w.firebase_app.options.databaseURL}/.json?print=pretty&auth=${id_token}`;\r\n\t\t\t\tnew_tab_json.click();\r\n\t\t\t} catch (err) {\r\n\t\t\t\tconsole.error(err);\r\n\t\t\t}\r\n\t\t});\r\n\t});\r\n</script>\r\n\r\n<nav class=\"mt-5 px-5\">\r\n\t{#if username}\r\n\t\t<span class=\"float-right\">\r\n\t\t\t<a href=\"https://www.reddit.com/u/{username}\" target=\"_blank\">u/<span id=\"username_wrapper\">{username}</span></a>\r\n\t\t\t<div class=\"btn-group dropdown\">\r\n\t\t\t\t<button bind:this={settings_btn} type=\"button\" class=\"btn btn-link pl-1 py-0\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\" data-display=\"static\" id=\"settings_btn\"><i class=\"fas fa-cog\"></i></button>\r\n\t\t\t\t<div bind:this={settings_menu} class=\"dropdown-menu dropdown-menu-right text-center mr-2 px-2 py-0\" id=\"settings_menu\">\r\n\t\t\t\t\t<a href=\"{globals_r.backend}/logout\">logout</a>\r\n\t\t\t\t\t<div class=\"dropdown-divider m-0\"></div>\r\n\t\t\t\t\t{#if show_data_anchors}\r\n\t\t\t\t\t\t<a bind:this={import_anchor} href=\"#\">import data</a>\r\n\t\t\t\t\t\t<div bind:this={import_notice} class=\"bg-info rounded text-light text-left line_height_1 mb-2 pb-1 d-none\">\r\n\t\t\t\t\t\t\t<p class=\"mx-1\">import data that you downloaded from <a href=\"https://www.reddit.com/settings/data-request\" target=\"_blank\" class=\"text-dark\">Reddit data request</a></p>\r\n\t\t\t\t\t\t\t<p class=\"mx-1\">extract the zip, then select the file(s) you want to import out of the following::</p>\r\n\t\t\t\t\t\t\t<ul class=\"mt-n3 ml-3 pl-3 pr-0\">\r\n\t\t\t\t\t\t\t\t<li><code class=\"text-dark\">saved_posts.csv</code></li>\r\n\t\t\t\t\t\t\t\t<li><code class=\"text-dark\">saved_comments.csv</code></li>\r\n\t\t\t\t\t\t\t\t<li><code class=\"text-dark\">posts.csv</code></li>\r\n\t\t\t\t\t\t\t\t<li><code class=\"text-dark\">comments.csv</code></li>\r\n\t\t\t\t\t\t\t\t<li><code class=\"text-dark\">post_votes.csv</code></li>\r\n\t\t\t\t\t\t\t\t<li><code class=\"text-dark\">hidden_posts.csv</code></li>\r\n\t\t\t\t\t\t\t</ul>\r\n\t\t\t\t\t\t\t<hr class=\"bg-muted mx-2 mb-2 mt-n2\"/>\r\n\t\t\t\t\t\t\t<form>\r\n\t\t\t\t\t\t\t\t<div class=\"form-group d-flex justify-content-center mb-0\">\r\n\t\t\t\t\t\t\t\t\t<input bind:this={files_input} type=\"file\" accept=\".csv\" class=\"form-control-file\" id=\"files_input\" style=\"display:none\" multiple/>\r\n\t\t\t\t\t\t\t\t\t<label for=\"files_input\" class=\"btn btn-outline-secondary border-dark bg-light text-dark py-0\" id=\"files_input_btn\">browse files</label>\r\n\t\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t\t<ul bind:this={selected_files_list} class=\"mb-0 ml-3 pl-3 pr-0\"></ul>\r\n\t\t\t\t\t\t\t\t<hr class=\"bg-muted mx-2 mb-2 mt-0\"/>\r\n\t\t\t\t\t\t\t\t<button bind:this={import_cancel_btn} class=\"btn btn-sm btn-secondary float-left ml-1\">cancel</button><button bind:this={import_confirm_btn} class=\"btn btn-sm btn-secondary float-right mr-1\">confirm</button>\r\n\t\t\t\t\t\t\t\t<div class=\"clearfix\"></div>\r\n\t\t\t\t\t\t\t</form>\r\n\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t<div class=\"dropdown-divider m-0\"></div>\r\n\t\t\t\t\t\t<a bind:this={export_anchor} href=\"#\">export data</a>\r\n\t\t\t\t\t\t<a bind:this={new_tab_json} href=\"#\" target=\"_blank\" class=\"d-none\"></a>\r\n\t\t\t\t\t\t<div class=\"dropdown-divider m-0\"></div>\r\n\t\t\t\t\t{/if}\r\n\t\t\t\t\t<a bind:this={purge_anchor} href=\"#\">purge account</a>\r\n\t\t\t\t\t<div bind:this={purge_warning} class=\"bg-danger rounded text-light text-left line_height_1 mb-2 pb-1 d-none\">\r\n\t\t\t\t\t\t<p class=\"mx-1\">are you sure you want to purge your eternity account?</p>\r\n\t\t\t\t\t\t<p class=\"mx-1\">your new Reddit items will not continue to sync to your database</p>\r\n\t\t\t\t\t\t<p class=\"mx-1\">this cannot be undone</p>\r\n\t\t\t\t\t\t<p class=\"mx-1 mb-0\">type <b>purge u/{username}</b> to confirm</p>\r\n\t\t\t\t\t\t<form>\r\n\t\t\t\t\t\t\t<div class=\"form-group d-flex justify-content-center mb-1\">\r\n\t\t\t\t\t\t\t\t<input bind:this={purge_input} class=\"form-control form-control-sm\" type=\"text\" id=\"purge_input\"/>\r\n\t\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\t<button bind:this={purge_cancel_btn} class=\"btn btn-sm btn-secondary float-left ml-1\">cancel</button><button bind:this={purge_confirm_btn} class=\"btn btn-sm btn-secondary float-right mr-1\">confirm</button>\r\n\t\t\t\t\t\t\t<div class=\"clearfix\"></div>\r\n\t\t\t\t\t\t</form>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t\t<div bind:this={purge_spinner_container} class=\"rounded my-2 py-5 d-none\" id=\"purge_spinner_container\">\r\n\t\t\t\t\t\t<div class=\"spinner-border text-secondary\" role=\"status\"><span class=\"sr-only\">loading...</span></div>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t\t<div bind:this={redirect_notice} class=\"rounded line_height_1 my-2 d-none\" id=\"redirect_notice\">\r\n\t\t\t\t\t\t<p>your account has been successfully purged from eternity</p>\r\n\t\t\t\t\t\t<p class=\"mb-0\">you will be automatically redirected in <b bind:this={redirect_countdown_wrapper}>?</b>s</p>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t</div>\r\n\t\t</span>\r\n\t{:else if show_return_to_app}\r\n\t\t<span class=\"float-right\">\r\n\t\t\t<a href=\"/\">return to app</a>\r\n\t\t</span>\r\n\t{/if}\r\n\t<div class=\"clearfix\"></div>\r\n</nav>\r\n{#if show_data_anchors}\r\n\t<div bind:this={modal} class=\"modal fade\" tabindex=\"-1\">\r\n\t\t<div class=\"modal-dialog modal-lg\">\r\n\t\t\t<div class=\"modal-content bg-secondary\">\r\n\t\t\t\t<div class=\"modal-header\">\r\n\t\t\t\t\t<h5 class=\"modal-title\">IMPORT STARTED</h5>\r\n\t\t\t\t\t<button type=\"button\" class=\"close\" data-dismiss=\"modal\"><span>&times;</span></button>\r\n\t\t\t\t</div>\r\n\t\t\t\t<div class=\"modal-body\">\r\n\t\t\t\t\t<span>import started. it may take up to a day to complete. do not try to re-import if you don't see all the items in eternity immediately. you can close/leave this page now</span>\r\n\t\t\t\t</div>\r\n\t\t\t\t<div class=\"modal-footer\">\r\n\t\t\t\t\t<button type=\"button\" class=\"btn btn-light\" data-dismiss=\"modal\">ok</button>\r\n\t\t\t\t</div>\r\n\t\t\t</div>\r\n\t\t</div>\r\n\t</div>\r\n{/if}\r\n"
  },
  {
    "path": "frontend/source/components/unlock.svelte",
    "content": "<script context=\"module\">\r\n\timport * as globals from \"frontend/source/globals.js\";\r\n\timport * as utils from \"frontend/source/utils.js\";\r\n\timport Navbar from \"frontend/source/components/navbar.svelte\";\r\n\r\n\timport * as svelte from \"svelte\";\r\n\r\n\tconst globals_r = globals.readonly;\r\n</script>\r\n<script>\r\n\texport let username;\r\n\t\r\n\tlet [\r\n\t\tinstruction_video_anchor,\r\n\t\tinstruction_video_wrapper,\r\n\t\tconfig_input,\r\n\t\tfile_input,\r\n\t\tfile_input_label,\r\n\t\tvalidate_btn,\r\n\t\tfirebase_alert_wrapper,\r\n\t\temail_input,\r\n\t\tconfirm_btn,\r\n\t\tverification_code_input,\r\n\t\tverify_btn,\r\n\t\temail_alert_wrapper,\r\n\t\tsave_and_continue_btn_wrapper,\r\n\t\tsave_and_continue_btn\r\n\t] = [];\r\n\t\r\n\tconst dispatch = svelte.createEventDispatcher();\r\n\r\n\tfunction handle_body_keydown(evt) {\r\n\t\tif (evt.key == \"Enter\") {\r\n\t\t\t(!save_and_continue_btn.hasAttribute(\"disabled\") ? save_and_continue_btn.click() : null);\r\n\t\t}\r\n\t}\r\n\r\n\tsvelte.onMount(() => {\r\n\t\tglobals_r.socket.emit(\"page\", \"unlock\");\r\n\r\n\t\tglobals_r.socket.on(\"alert\", (alert, msg, type) => {\r\n\t\t\tswitch (alert) {\r\n\t\t\t\tcase \"firebase\":\r\n\t\t\t\t\tutils.show_alert(firebase_alert_wrapper, msg, type);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"email\":\r\n\t\t\t\t\tutils.show_alert(email_alert_wrapper, msg, type);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tglobals_r.socket.on(\"disable button\", (button) => {\r\n\t\t\tswitch (button) {\r\n\t\t\t\tcase \"validate\":\r\n\t\t\t\t\tvalidate_btn.setAttribute(\"disabled\", \"\");\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"confirm\":\r\n\t\t\t\t\tconfirm_btn.setAttribute(\"disabled\", \"\");\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"verify\":\r\n\t\t\t\t\tverify_btn.setAttribute(\"disabled\", \"\");\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tglobals_r.socket.on(\"enable button\", (button) => {\r\n\t\t\tswitch (button) {\r\n\t\t\t\tcase \"verify\":\r\n\t\t\t\t\tverify_btn.removeAttribute(\"disabled\");\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"save_and_continue\":\r\n\t\t\t\t\tjQuery('[data-toggle=\"tooltip\"]').tooltip(\"disable\");\r\n\t\t\t\t\tsave_and_continue_btn.removeAttribute(\"disabled\");\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tglobals_r.socket.on(\"switch page to loading\", () => {\r\n\t\t\tdispatch(\"dispatch\", \"switch page to loading\");\r\n\t\t});\r\n\r\n\t\tjQuery('[data-toggle=\"tooltip\"]').tooltip(\"enable\");\r\n\r\n\t\tinstruction_video_anchor.addEventListener(\"click\", (evt) => {\r\n\t\t\tevt.preventDefault();\r\n\t\t\tinstruction_video_wrapper.classList.toggle(\"d-none\");\r\n\t\t});\r\n\r\n\t\tfile_input.addEventListener(\"input\", (evt) => {\r\n\t\t\tfile_input_label.innerText = file_input.files[0].name;\r\n\t\t});\r\n\r\n\t\tconfig_input.addEventListener(\"keydown\", (evt) => {\r\n\t\t\tswitch (evt.key) {\r\n\t\t\t\tcase \"Enter\":\r\n\t\t\t\t\tvalidate_btn.click();\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase \"Tab\":\r\n\t\t\t\t\tevt.preventDefault();\r\n\t\t\t\t\temail_input.focus();\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tvalidate_btn.addEventListener(\"click\", (evt) => {\r\n\t\t\tif (!config_input.value) {\r\n\t\t\t\tutils.show_alert(firebase_alert_wrapper, \"provide the web app config\", \"warning\");\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tlet web_app_config = null;\r\n\t\t\ttry {\r\n\t\t\t\tweb_app_config = JSON.parse(config_input.value.replace(/(\\s)/g, \"\").replace(\";\", \"\").replace(\"{\", '{\"').replaceAll(':\"', '\":\"').replaceAll('\",', '\",\"'));\r\n\t\t\t} catch (err) {\r\n\t\t\t\tconsole.error(err);\r\n\t\t\t\tutils.show_alert(firebase_alert_wrapper, \"this is not a Firebase web app config\", \"danger\");\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tif (!file_input.value) {\r\n\t\t\t\tutils.show_alert(firebase_alert_wrapper, \"provide the service account key file\", \"warning\");\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tconst file = file_input.files[0];\r\n\t\t\tconst filename = file.name;\r\n\t\t\tconst filesize = file.size; // in binary bytes\r\n\t\t\tconst filesize_limit = 3072; // 3kb in binary bytes. firebase service account key files should be ~2.3kb\r\n\r\n\t\t\tif (filename.split(\".\").pop().toLowerCase() != \"json\" || filesize > filesize_limit) {\r\n\t\t\t\tutils.show_alert(firebase_alert_wrapper, \"this is not a Firebase service account key file\", \"danger\");\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tconst data = new FormData();\r\n\t\t\tdata.append(\"key\", file, file.name);\r\n\r\n\t\t\tconst request = new XMLHttpRequest();\r\n\t\t\trequest.open(\"post\", `${globals_r.backend}/upload`);\r\n\t\t\trequest.responseType = \"json\";\r\n\r\n\t\t\trequest.addEventListener(\"error\", (evt) => {\r\n\t\t\t\tutils.show_alert(firebase_alert_wrapper, \"save error\", \"danger\");\r\n\t\t\t});\r\n\r\n\t\t\trequest.onreadystatechange = function () {\r\n\t\t\t\tif (this.readyState == 4 && this.status == 200) {\r\n\t\t\t\t\tutils.show_alert(firebase_alert_wrapper, '<div class=\"d-flex justify-content-center pt-1\"><div class=\"dot-carousel mr-4\"></div><span class=\"mt-n1\">validating key and database</span><div class=\"dot-carousel ml-4\"></div></div>', \"success\");\r\n\r\n\t\t\t\t\tsetTimeout(() => {\r\n\t\t\t\t\t\tglobals_r.socket.emit(\"validate firebase info\", web_app_config);\r\n\t\t\t\t\t}, 2000);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\r\n\t\t\trequest.send(data);\r\n\t\t});\r\n\r\n\t\temail_input.addEventListener(\"keydown\", (evt) => {\r\n\t\t\t(evt.key == \"Enter\" ? confirm_btn.click() : null);\r\n\t\t});\r\n\r\n\t\tconfirm_btn.addEventListener(\"click\", (evt) => {\r\n\t\t\tconst email = email_input.value.trim();\r\n\r\n\t\t\tif (!(email && email.includes(\"@\") && email.includes(\".\") && email.length >= 7)) {\r\n\t\t\t\tutils.show_alert(email_alert_wrapper, \"this is not an email address\", \"warning\");\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tglobals_r.socket.emit(\"confirm email\", email);\r\n\t\t\tverification_code_input.focus();\r\n\t\t});\r\n\r\n\t\tverification_code_input.addEventListener(\"keydown\", (evt) => {\r\n\t\t\t(evt.key == \"Enter\" ? verify_btn.click() : null);\r\n\t\t});\r\n\r\n\t\tverification_code_input.addEventListener(\"keyup\", (evt) => {\r\n\t\t\tevt.target.value = evt.target.value.toUpperCase();\r\n\t\t});\r\n\r\n\t\tverify_btn.addEventListener(\"click\", (evt) => {\r\n\t\t\tconst code = verification_code_input.value;\r\n\t\t\tglobals_r.socket.emit(\"verify code\", username, code);\r\n\t\t});\r\n\r\n\t\tsave_and_continue_btn_wrapper.addEventListener(\"mouseenter\", (evt) => {\r\n\t\t\t(save_and_continue_btn.disabled ? jQuery('[data-toggle=\"tooltip\"]').tooltip(\"show\") : null);\r\n\t\t});\r\n\r\n\t\tsave_and_continue_btn_wrapper.addEventListener(\"mouseleave\", (evt) => {\r\n\t\t\t(save_and_continue_btn.disabled ? jQuery('[data-toggle=\"tooltip\"]').tooltip(\"hide\") : null);\r\n\t\t});\r\n\r\n\t\tsave_and_continue_btn.addEventListener(\"click\", (evt) => {\r\n\t\t\tevt.target.innerHTML = '<div class=\"d-flex justify-content-center pt-2\"><div class=\"dot-carousel mr-4\"></div><span class=\"mt-n2\">saving</span><div class=\"dot-carousel ml-4\"></div></div>';\r\n\r\n\t\t\tsetTimeout(() => {\r\n\t\t\t\tglobals_r.socket.emit(\"save firebase info and email\");\r\n\t\t\t}, 2000);\r\n\t\t});\r\n\t});\r\n\tsvelte.onDestroy(() => {\r\n\t\tglobals_r.socket.off(\"alert\");\r\n\t\tglobals_r.socket.off(\"disable button\");\r\n\t\tglobals_r.socket.off(\"allow save and continue\");\r\n\t\tglobals_r.socket.off(\"switch page to loading\");\r\n\t});\r\n</script>\r\n\r\n<svelte:body on:keydown={handle_body_keydown}/>\r\n<Navbar username={username}/>\r\n<div class=\"text-center mt-3\">\r\n\t<h1 class=\"display-4\">{globals_r.app_name}</h1>\r\n\t<div id=\"unlock_container\" class=\"card card-body bg-dark text-left mt-3 pb-3\">\r\n\t\t<div class=\"form-group\">\r\n\t\t\t<div class=\"text-center\">\r\n\t\t\t\t<b><a bind:this={instruction_video_anchor} href=\"#\">SETUP GUIDE VIDEO</a></b>\r\n\t\t\t\t<span bind:this={instruction_video_wrapper} class=\"no_bullet embed-responsive embed-responsive-16by9 d-none\"><iframe title=\"firebase setup guide\" class=\"embed-responsive-item\" src=\"https://www.youtube.com/embed/KPxppovc56A\" allow=\"fullscreen\"></iframe></span>\r\n\t\t\t</div>\r\n\t\t\t<p class=\"mt-4\">to use eternity, you will need to go to <a href=\"https://console.firebase.google.com\" target=\"_blank\">Firebase console</a> and</p>\r\n\t\t\t<ul class=\"line_height_1 mt-n2\">\r\n\t\t\t\t<li class=\"mt-2\">create a new Firebase project <span class=\"text-light\">named <b>{`eternity-${username.split(\"_\").join(\"-\")}`}</b></span></li>\r\n\t\t\t\t<li class=\"mt-2\">create a Realtime Database where your Reddit items will be stored</li>\r\n\t\t\t\t<li class=\"mt-2\">set the Realtime Database read and write security rules to <b>\"auth.token.owner == true\"</b></li>\r\n\t\t\t\t<li class=\"mt-2\">enable Authentication from domain <b>eternity.portals.sh</b></li>\r\n\t\t\t\t<li class=\"mt-2\">get a service account key file and a web app config</li>\r\n\t\t\t\t<li class=\"no_bullet d-flex mt-2\">\r\n\t\t\t\t\t<div class=\"w-100\">\r\n\t\t\t\t\t\t<div class=\"custom-file\">\r\n\t\t\t\t\t\t\t<input bind:this={file_input} class=\"custom-file-input\" type=\"file\" accept=\".json\" id=\"file_input\"/>\r\n\t\t\t\t\t\t\t<label bind:this={file_input_label} for=\"file_input\" class=\"custom-file-label text-left bg-light\">Firebase service account key file</label>\r\n\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t<input bind:this={config_input} type=\"text\" class=\"form-control bg-light mt-1\" placeholder=\"Firebase web app config\"/>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t\t<button bind:this={validate_btn} class=\"btn btn-primary shadow-none ml-2\">validate</button>\r\n\t\t\t\t</li>\r\n\t\t\t\t<li class=\"no_bullet mt-2\"><div bind:this={firebase_alert_wrapper}></div></li>\r\n\t\t\t\t<li class=\"mt-2\">provide an email for account notifications and recovery</li>\r\n\t\t\t\t<li class=\"no_bullet mt-2\">\r\n\t\t\t\t\t<div class=\"d-flex w-100\">\r\n\t\t\t\t\t\t<input bind:this={email_input} type=\"text\" class=\"form-control bg-light\" placeholder=\"email address\"/>\r\n\t\t\t\t\t\t<button bind:this={confirm_btn} class=\"btn btn-primary shadow-none ml-2\">confirm</button>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t\t<div class=\"d-flex w-100 mt-2\">\r\n\t\t\t\t\t\t<input bind:this={verification_code_input} type=\"text\" class=\"form-control bg-light\" placeholder=\"verification code\"/>\r\n\t\t\t\t\t\t<button bind:this={verify_btn} class=\"btn btn-primary shadow-none ml-2\" disabled>verify</button>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</li>\r\n\t\t\t\t<li class=\"no_bullet mt-2\"><div bind:this={email_alert_wrapper}></div></li>\r\n\t\t\t</ul>\r\n\t\t\t<div bind:this={save_and_continue_btn_wrapper} data-toggle=\"tooltip\" data-trigger=\"manual\" data-placement=\"top\" title=\"complete the required steps above first\">\r\n\t\t\t\t<button bind:this={save_and_continue_btn} class=\"btn btn-primary shadow-none w-100 mt-3\" disabled>save and continue</button>\r\n\t\t\t</div>\r\n\t\t</div>\r\n\t</div>\r\n</div>\r\n"
  },
  {
    "path": "frontend/source/global.d.ts",
    "content": "/// <reference types=\"@sveltejs/kit\"/>\n"
  },
  {
    "path": "frontend/source/globals.js",
    "content": "import * as app_env from \"$app/env\";\nimport * as env_static_public from \"$env/static/public\";\nimport * as store from \"svelte/store\";\nimport * as socket_io_client from \"socket.io-client\";\n\nconst readonly = {\n\tapp_name: \"eternity\",\n\tdescription: \"bypass Reddit's 1000-item listing limits by externally storing your Reddit items (saved, created, upvoted, downvoted, hidden) in your own database\",\n\trepo: \"https://github.com/jc9108/eternity\",\n\tbackend: (env_static_public.RUN == \"dev\" ? \"/backend\" : \"\"),\n\tsocket: socket_io_client.io((env_static_public.RUN == \"dev\" ? `http://${(app_env.browser ? window.location.hostname : \"localhost\")}:${Number.parseInt(env_static_public.PORT)+1}` : \"\")),\n\tportals: (env_static_public.RUN == \"dev\" ? `http://${(app_env.browser ? window.location.hostname : \"localhost\")}:1025` : \"https://portals.sh\")\n};\n\nconst writable = store.writable({\n\tfirebase_app: null,\n\tfirebase_auth: null,\n\tfirebase_db: null\n});\n\nexport {\n\treadonly,\n\twritable\n};\n"
  },
  {
    "path": "frontend/source/hooks.js",
    "content": "export async function handle(obj) {\n\tconst response = await obj.resolve(obj.event, {\n\t\tssr: false\n\t});\n\treturn response;\n}\n"
  },
  {
    "path": "frontend/source/routes/__error.svelte",
    "content": "<script context=\"module\">\n\timport * as globals from \"frontend/source/globals.js\";\n\n\timport * as svelte from \"svelte\";\n\timport axios from \"axios\";\n\n\tconst globals_r = globals.readonly;\n\n\tfunction ensure_redirect(current_path) {\n\t\t(current_path == \"/\" ? window.history.pushState(null, \"\", \"/error\") : null); // if current path is already index, change the path so that \"return to app\" will actually redirect to index\n\t}\n\n\texport async function load(obj) {\n\t\tconsole.log(obj.status);\n\t\tconsole.log(obj.error.message);\n\n\t\tif (obj.status != 404) {\n\t\t\tensure_redirect(obj.url.pathname);\n\n\t\t\treturn {\n\t\t\t\tprops: {\n\t\t\t\t\thttp_status: obj.status\n\t\t\t\t}\n\t\t\t};\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tawait axios.get(globals_r.backend + obj.url.pathname); // should throw an error\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(err);\n\n\t\t\t\tensure_redirect(obj.url.pathname);\n\n\t\t\t\treturn {\n\t\t\t\t\tprops: {\n\t\t\t\t\t\thttp_status: Number.parseInt(err.message.split(\" \").slice(-1)[0])\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t};\n</script>\n<script>\n\texport let http_status;\n\n\tsvelte.onMount(() => {\n\t\tglobals_r.socket.emit(\"route\", http_status);\n\t});\n</script>\n\n<svelte:head>\n\t<title>{http_status}</title>\n\t<meta name=\"description\" content={http_status}/>\n</svelte:head>\n<div class=\"text-center mt-5 pt-5\">\n\t<a href=\"https://www.google.com/search?q=http+status+{http_status}\" target=\"_blank\" class=\"display-1\">{http_status}</a>\n\t<br/>\n\t<a href=\"/\" class=\"display-3\">return to app</a>\n</div>\n"
  },
  {
    "path": "frontend/source/routes/__layout.svelte",
    "content": "<script context=\"module\">\r\n\timport * as globals from \"frontend/source/globals.js\";\r\n\timport Footer from \"frontend/source/components/footer.svelte\";\r\n\r\n\timport * as svelte from \"svelte\";\r\n\timport firebase from \"firebase\";\r\n\r\n\tconst globals_r = globals.readonly;\r\n\tconst globals_w = globals.writable;\r\n\r\n\texport async function load(obj) {\r\n\t\tlet interval_id = null;\r\n\t\ttry {\r\n\t\t\tawait new Promise((resolve, reject) => {\r\n\t\t\t\tconst timeout_id = setTimeout(() => {\r\n\t\t\t\t\treject(\"socket connection attempt timed out\");\r\n\t\t\t\t}, 5000);\r\n\r\n\t\t\t\tinterval_id = setInterval(() => {\r\n\t\t\t\t\tif (globals_r.socket.connected) {\r\n\t\t\t\t\t\tclearTimeout(timeout_id);\r\n\t\t\t\t\t\tclearInterval(interval_id);\r\n\t\t\t\t\t\tresolve();\r\n\t\t\t\t\t}\r\n\t\t\t\t}, 100);\r\n\t\t\t});\r\n\t\t\t\r\n\t\t\treturn {\r\n\t\t\t\tstatus: 200\r\n\t\t\t};\r\n\t\t} catch (err) {\r\n\t\t\tconsole.error(err);\r\n\t\t\tclearInterval(interval_id);\r\n\r\n\t\t\treturn {\r\n\t\t\t\tstatus: 408\r\n\t\t\t};\r\n\t\t}\r\n\t};\r\n</script>\r\n<script>\r\n\tsvelte.onMount(() => {\r\n\t\tglobals_r.socket.emit(\"layout mounted\");\r\n\r\n\t\tglobals_r.socket.on(\"create firebase instances\", async (config, auth_token) => {\r\n\t\t\ttry {\r\n\t\t\t\t$globals_w.firebase_app = firebase.initializeApp(config);\r\n\t\t\t\t$globals_w.firebase_auth = firebase.auth($globals_w.firebase_app);\r\n\t\t\t\tawait $globals_w.firebase_auth.signInWithCustomToken(auth_token);\r\n\t\t\t\t$globals_w.firebase_db = firebase.database($globals_w.firebase_app);\r\n\t\t\t} catch (err) {\r\n\t\t\t\tconsole.error(err);\r\n\t\t\t}\r\n\t\t});\r\n\t});\r\n\tsvelte.onDestroy(() => {\r\n\t\tglobals_r.socket.off(\"create firebase instances\");\r\n\r\n\t\t($globals_w.firebase_app ? $globals_w.firebase_app.delete().catch((err) => console.error(err)) : null);\r\n\t});\r\n</script>\r\n\r\n<div class=\"container-fluid text-light\">\r\n\t<div class=\"row d-flex justify-content-center\">\r\n\t\t<content class=\"col-12 col-sm-11 col-md-10 col-lg-9 col-xl-8\">\r\n\t\t\t<slot></slot>\r\n\t\t\t<div class=\"text-center my-4 pt-2\">\r\n\t\t\t\t<a href={globals_r.repo} target=\"_blank\"><i id=\"bottom_gh\" class=\"fab fa-github\"></i></a>\r\n\t\t\t</div>\r\n\t\t</content>\r\n\t\t<Footer/>\r\n\t</div>\r\n</div>\r\n"
  },
  {
    "path": "frontend/source/routes/about.svelte",
    "content": "<script context=\"module\">\r\n\timport * as globals from \"frontend/source/globals.js\";\r\n\timport Navbar from \"frontend/source/components/navbar.svelte\";\r\n\r\n\timport * as svelte from \"svelte\";\r\n\r\n\tconst globals_r = globals.readonly;\r\n</script>\r\n<script>\r\n\tsvelte.onMount(() => {\r\n\t\tglobals_r.socket.emit(\"route\", \"about\");\r\n\t});\r\n</script>\r\n\r\n<svelte:head>\r\n\t<title>{globals_r.app_name} — about</title>\r\n\t<meta name=\"description\" content={globals_r.description}/>\r\n</svelte:head>\r\n<Navbar show_return_to_app={true}/>\r\n<div class=\"text-center mt-3\">\r\n\t<h1 class=\"display-4\">{globals_r.app_name}</h1>\r\n\t<div class=\"card card-body bg-dark text-left mt-3 pb-3\">\r\n\t\t<div class=\"form-group mb-0\">\r\n\t\t\t<p>terms of service</p>\r\n\t\t\t<ul class=\"line_height_1 mt-n2\">\r\n\t\t\t\t<li class=\"mt-3\">this app is released under the <a target=\"_blank\" href=\"https://choosealicense.com/licenses/agpl-3.0\">AGPL3 License</a></li>\r\n\t\t\t\t<li class=\"mt-2\">you must log in to eternity at least once every 6 months or else your eternity account will be marked inactive and your new Reddit items will not continue to sync to your database</li>\r\n\t\t\t\t<li class=\"mt-2\"><a href=\"https://firebase.google.com/pricing\" target=\"_blank\">Firebase free tier</a> provides 1gb disk storage, which should be enough to last you a very long time (e.g., 5000 items ≈ 1.5mb = 0.0015gb). if your database usage eventually exceeds the free tier, you will need to upgrade your Firebase plan in order for eternity to continue storing your new Reddit items. or, you can choose to export out the existing data and wipe the database to continue for free</li>\r\n\t\t\t\t<li class=\"mt-2\">do not edit any of the Firebase project settings or database contents directly from Firebase. if you do and your eternity instance stops working, you may have to restart</li>\r\n\t\t\t</ul>\r\n\t\t\t<p class=\"mt-4\">privacy policy</p>\r\n\t\t\t<ul class=\"line_height_1 mt-n2\">\r\n\t\t\t\t<li class=\"mt-3\">login is handled directly by Reddit (<a href=\"https://github.com/reddit-archive/reddit/wiki/OAuth2\">oauth2</a>) so your password is never sent to eternity</li>\r\n\t\t\t\t<li class=\"mt-2\">eternity uses your Reddit authorization to continuously retrieve your new Reddit items, and stores them in your database using the Firebase info you provided</li>\r\n\t\t\t\t<li class=\"mt-2\">no user info is shared or sold. no info is used for any purposes other than the functioning of this app</li>\r\n\t\t\t</ul>\r\n\t\t\t<p class=\"mt-4\">support</p>\r\n\t\t\t<ul class=\"line_height_1 mt-n2\">\r\n\t\t\t\t<li class=\"mt-3\"><a href={`${globals_r.repo}/issues`} target=\"_blank\">issue tracker</a></li>\r\n\t\t\t\t<li class=\"mt-2\"><a href={`${globals_r.repo}/discussions/categories/q-a`} target=\"_blank\">general questions</a></li>\r\n\t\t\t\t<li class=\"mt-2\"><a href=\"mailto:eternity@portals.sh\">private questions</a></li>\r\n\t\t\t</ul>\r\n\t\t</div>\r\n\t</div>\r\n</div>\r\n"
  },
  {
    "path": "frontend/source/routes/index.svelte",
    "content": "<script context=\"module\">\r\n\timport * as globals from \"frontend/source/globals.js\";\r\n\timport Landing from \"frontend/source/components/landing.svelte\";\r\n\timport Unlock from \"frontend/source/components/unlock.svelte\";\r\n\timport Loading from \"frontend/source/components/loading.svelte\";\r\n\timport Access from \"frontend/source/components/access.svelte\";\r\n\r\n\timport * as svelte from \"svelte\";\r\n\timport axios from \"axios\";\r\n\r\n\tlet username = null;\r\n\r\n\tconst globals_r = globals.readonly;\r\n\r\n\texport async function load(obj) {\r\n\t\ttry {\r\n\t\t\tconst response = await axios.get(`${globals_r.backend}/authentication_check?socket_id=${globals_r.socket.id}`);\r\n\t\t\tconst response_data = response.data;\r\n\r\n\t\t\tusername = response_data.username; // undefined if use_page is \"landing\"\r\n\r\n\t\t\treturn {\r\n\t\t\t\tstatus: 200,\r\n\t\t\t\tprops: {\r\n\t\t\t\t\tuse_page: response_data.use_page\r\n\t\t\t\t}\r\n\t\t\t};\r\n\t\t} catch (err) {\r\n\t\t\tconsole.error(err);\r\n\r\n\t\t\tif (Number.parseInt(err.message.split(\" \").slice(-1)[0]) == 401) { // backend deserializeUser error\r\n\t\t\t\treturn {\r\n\t\t\t\t\tstatus: 401\r\n\t\t\t\t};\r\n\t\t\t} else { // get request failed\r\n\t\t\t\treturn {\r\n\t\t\t\t\tstatus: 503\r\n\t\t\t\t};\t\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n</script>\r\n<script>\r\n\texport let use_page;\r\n\r\n\tlet active_page = null;\r\n\r\n\tfunction handle_component_dispatch(evt) {\r\n\t\tswitch (evt.detail) {\r\n\t\t\tcase \"switch page to loading\":\r\n\t\t\t\tactive_page = Loading;\r\n\t\t\t\tbreak;\r\n\t\t\tcase \"switch page to access\":\r\n\t\t\t\tactive_page = Access;\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\r\n\tswitch (use_page) {\r\n\t\tcase \"landing\":\r\n\t\t\tactive_page = Landing;\r\n\t\t\tbreak;\r\n\t\tcase \"unlock\":\r\n\t\t\tactive_page = Unlock;\r\n\t\t\tbreak;\r\n\t\tcase \"loading\":\r\n\t\t\tactive_page = Loading;\r\n\t\t\tbreak;\r\n\t\tcase \"access\":\r\n\t\t\tactive_page = Access;\r\n\t\t\tbreak;\r\n\t\tdefault:\r\n\t\t\tbreak;\r\n\t}\r\n\r\n\tsvelte.onMount(() => {\r\n\t\tif (window.location.href.endsWith(\"/#_\")) { // from reddit oauth callback\r\n\t\t\twindow.history.pushState(null, \"\", window.location.href.slice(0, -3));\r\n\t\t}\r\n\r\n\t\tglobals_r.socket.emit(\"route\", \"index\");\r\n\t});\r\n</script>\r\n\r\n<svelte:head>\r\n\t<title>{globals_r.app_name}</title>\r\n\t<meta name=\"description\" content={globals_r.description}/>\r\n</svelte:head>\r\n<svelte:component this={active_page} on:dispatch={handle_component_dispatch} username={username}/>\r\n"
  },
  {
    "path": "frontend/source/utils.js",
    "content": "function now_epoch() {\n\tconst now_epoch = Math.floor(Date.now() / 1000);\n\treturn now_epoch;\n}\n\nfunction epoch_to_formatted_datetime(epoch) {\n\tlet formatted_datetime = new Date(epoch * 1000).toLocaleString(\"en-GB\", {timeZone: \"UTC\", timeZoneName: \"short\", hour12: true}).toUpperCase().split(\"/\").join(\"-\").replace(\",\", \"\").replace(\" AM\", \":AM\").replace(\" PM\", \":PM\");\n\tconst split = formatted_datetime.split(\" \");\n\t(split[1][1] == \":\" ? split[1] = \"0\"+split[1] : null);\n\tformatted_datetime = split.join(\" \");\n\treturn formatted_datetime;\n}\n\nfunction time_since(epoch) {\n\tconst epoch_diff = now_epoch() - epoch;\n\tif (epoch_diff/31536000 >= 1) {\n\t\treturn Math.floor(epoch_diff/31536000)+\"y\";\n\t} else if (epoch_diff/2592000 >= 1) {\n\t\treturn Math.floor(epoch_diff/2592000)+\"m\";\n\t} else if (epoch_diff/86400 >= 1) {\n\t\treturn Math.floor(epoch_diff/86400)+\"d\";\n\t} else if (epoch_diff/3600 >= 1) {\n\t\treturn Math.floor(epoch_diff/3600)+\"h\";\n\t} else if (epoch_diff/60 >= 1) {\n\t\treturn Math.floor(epoch_diff/60)+\"m\";\n\t} else {\n\t\treturn epoch_diff+\"s\";\n\t}\n}\n\nfunction shake_element(element) {\n\telement.classList.add(\"shake\");\n\tsetTimeout(() => {\n\t\telement.classList.remove(\"shake\");\n\t}, 300);\n}\n\nfunction show_alert(alert_wrapper, message, type) {\n\talert_wrapper.innerHTML = `\n\t\t<div id=\"alert\" class=\"alert alert-${type} fade show text-center mb-0 p-1\" role=\"alert\">\n\t\t\t<span>${message}</span>\n\t\t</div>\n\t`;\n}\n\nexport {\n\tepoch_to_formatted_datetime,\n\ttime_since,\n\tshake_element,\n\tshow_alert\n};\n"
  },
  {
    "path": "frontend/static/style.css",
    "content": "@import url(\"https://fonts.googleapis.com/css?family=Poppins\");\r\n@import url(\"https://fonts.googleapis.com/css?family=Consolas\");\r\n@import url(\"https://fonts.googleapis.com/css?family=Noto+Sans\");\r\n\r\nhtml {\r\n\tposition: relative;\r\n\tmin-height: 100%;\r\n}\r\n\r\nbody {\r\n\tfont-family: \"Poppins\", sans-serif;\r\n\tbackground: rgb(43, 43, 43);\r\n}\r\n\r\nbody::-webkit-scrollbar {\r\n\twidth: 16px;\r\n}\r\n\r\nbody::-webkit-scrollbar-track {\r\n\tbackground: rgb(43, 43, 43);\r\n} body.light_mode::-webkit-scrollbar-track {\r\n\tbackground: rgb(212, 212, 212);\r\n}\r\n\r\nbody::-webkit-scrollbar-thumb {\r\n\tbackground: rgb(80, 80, 80);\r\n\tborder: 5px solid;\r\n\tborder-color: rgb(43, 43, 43);\r\n\tborder-radius: 16px;\r\n} body.light_mode::-webkit-scrollbar-thumb {\r\n\tbackground: rgb(175, 175, 175);\r\n\tborder-color: rgb(212, 212, 212);\r\n}\r\n\r\nbody::-webkit-scrollbar-thumb:hover {\r\n\tborder: 3px solid;\r\n\tborder-color: rgb(43, 43, 43);\r\n} body.light_mode::-webkit-scrollbar-thumb:hover {\r\n\tborder-color: rgb(212, 212, 212);\r\n}\r\n\r\ncontent {\r\n\tpadding: 0 0 6.5rem 0; /* match bottom to footer height */\r\n}\r\n\r\nfooter {\r\n\tposition: absolute;\r\n\twidth: 100%;\r\n\theight: 6.5rem; /* space from bottom */\r\n\tbottom: 0;\r\n}\r\n\r\na {\r\n\tcolor: #8ab4f8;\r\n\ttext-decoration: none;\r\n}\r\n\r\na:hover {\r\n\tcolor: #8ab4f8;\r\n\ttext-decoration: underline;\r\n}\r\n\r\na:visited {\r\n\tcolor: #f28b82;\r\n}\r\n\r\nimg {\r\n\twidth: 20px;\r\n\theight: 20px;\r\n}\r\n\r\n.invert {\r\n\tfilter: invert(1) hue-rotate(180deg);\r\n}\r\n\r\n.anti_invert {\r\n\tfilter: invert(1) hue-rotate(180deg);\r\n}\r\n\r\n.boxed {\r\n\tborder: 1px solid;\r\n\tborder-color: rgb(200, 200, 200);\r\n}\r\n\r\n.consolas {\r\n\tfont-family: \"Consolas\", sans-serif;\r\n}\r\n\r\n.dropdown-toggle {\r\n\tcolor: #8ab4f8;\r\n}\r\n\r\n.dropdown-toggle:focus {\r\n\tcolor: rgb(248, 249, 250);\r\n\tbox-shadow: none;\r\n}\r\n\r\n.font_size_10 {\r\n\tfont-size: 10px;\r\n}\r\n\r\n.line_height_1 {\r\n\tline-height: 1;\r\n}\r\n\r\n.spinner-border {\r\n\twidth: 4rem;\r\n\theight: 4rem;\r\n}\r\n\r\n.shake {\r\n\tposition: relative;\r\n\tanimation: shake 100ms linear;\r\n\tanimation-iteration-count: 3;\r\n} @keyframes shake {\r\n\t0% {left: -5px;}\r\n\t100% {right: -5px;}\r\n}\r\n\r\n.list-group-item {\r\n\tbackground: rgb(52, 58, 64);\r\n}\r\n\r\n.list-group-item:hover {\r\n\tbackground: rgb(62, 68, 74);\r\n\tcursor: pointer;\r\n}\r\n\r\n.list-group-item:focus {\r\n\tbackground: rgb(67, 73, 79);\r\n}\r\n\r\n.bootstrap-select > .dropdown-menu > .inner {\r\n\toverscroll-behavior: none;\r\n}\r\n\r\n.noto_sans {\r\n\tfont-family: \"Noto Sans\", sans-serif;\r\n}\r\n\r\n.popover {\r\n\ttext-align: center;\r\n\twidth: 220px;\r\n}\r\n\r\n.row_1_popover_btn {\r\n\twidth: 30%;\r\n}\r\n\r\n.row_2_popover_btn {\r\n\twidth: 35%;\r\n}\r\n\r\n.skeleton_item { /* https://uxdesign.cc/using-css-design-a-simple-skeleton-loader-57d884cd3547 */\r\n\twidth: 100%;\r\n\theight: 14.3%; /* i.e., 7 of them fills up skeleton_list */\r\n\tdisplay: block;\r\n\tbackground: rgb(108, 117, 125) linear-gradient(\r\n\t\tto right,\r\n\t\trgba(255, 255, 255, 0),\r\n\t\trgba(255, 255, 255, 0.5) 40%,\r\n\t\trgba(255, 255, 255, 0) 80%\r\n\t);\r\n\tbackground-size: 50px 500px;\r\n\tbackground-position: 0 0;\r\n\tbackground-repeat: repeat-y;\r\n\tanimation: shine 1s infinite;\r\n} @keyframes shine {\r\n\t50% {background-position: 100% 0;}\r\n}\r\n\r\n.custom-file {\r\n\toverflow: hidden;\r\n}\r\n\r\n.custom-file-label {\r\n\toverflow: hidden;\r\n}\r\n\r\n.custom-file-label::after {\r\n\tcontent: \"browse\";\r\n}\r\n\r\n.no_bullet {\r\n\tlist-style-type: none;\r\n}\r\n\r\n#dropdown_menu {\r\n\tleft: 50%;\r\n\tright: auto;\r\n\ttransform: translate(-50%, 0);\r\n\tborder-bottom: 15px solid;\r\n\tborder-color: rgb(43, 43, 43);\r\n\twidth: 180px;\r\n} #dropdown_menu.light_mode {\r\n\tborder-color: rgb(212, 212, 212);\r\n}\r\n\r\n#bottom_gh {\r\n\tfont-size: 60px;\r\n\tcolor: rgb(60, 60, 60);\r\n}\r\n\r\n#bottom_gh:hover {\r\n\tcolor: rgb(120, 120, 120);\r\n}\r\n\r\n#login_btn {\r\n\tbackground: rgb(20, 132, 214);\r\n\twidth: 250px;\r\n}\r\n\r\n#login_btn:hover {\r\n\tbackground: rgb(30, 142, 224);\r\n}\r\n\r\n#login_btn:active {\r\n\tbackground: rgb(40, 152, 234);\r\n}\r\n\r\n#login_anchor:hover {\r\n\ttext-decoration: none;\r\n}\r\n\r\n#reddit_logo {\r\n\theight: 55px;\r\n\twidth: auto;\r\n}\r\n\r\n#settings_btn {\r\n\tcolor: #8ab4f8;\r\n}\r\n\r\n#settings_btn:hover {\r\n\tcolor: rgb(0, 86, 179);\r\n}\r\n\r\n#settings_btn:focus {\r\n\tcolor: rgb(248, 249, 250);\r\n\tbox-shadow: none;\r\n}\r\n\r\n#settings_menu {\r\n\twidth: 195px;\r\n}\r\n\r\n#purge_input {\r\n\twidth: 95%;\r\n}\r\n\r\n#purge_spinner_container {\r\n\tbackground: pink;\r\n}\r\n\r\n#redirect_notice {\r\n\tbackground: pink;\r\n\tcolor: black;\r\n}\r\n\r\n#last_updated_wrapper_1 {\r\n\tcursor: pointer;\r\n}\r\n\r\n#item_list, #skeleton_list {\r\n\theight: 75vh;\r\n\toverflow-x: hidden;\r\n\toverflow-y: scroll;\r\n\toverscroll-behavior: none;\r\n}\r\n\r\n#item_list::-webkit-scrollbar, #skeleton_list::-webkit-scrollbar {\r\n\twidth: 12px;\r\n}\r\n\r\n#item_list::-webkit-scrollbar-track, #skeleton_list::-webkit-scrollbar-track {\r\n\tbackground: rgb(52, 58, 64);\r\n\tborder-radius: 5px;\r\n}\r\n\r\n#item_list::-webkit-scrollbar-thumb, #skeleton_list::-webkit-scrollbar-thumb {\r\n\tbackground: rgb(108, 117, 125);\r\n\tborder: 3px solid;\r\n\tborder-color: rgb(52, 58, 64);\r\n\tborder-radius: 12px;\r\n}\r\n\r\n#item_list::-webkit-scrollbar-thumb:hover, #skeleton_list::-webkit-scrollbar-thumb:hover {\r\n\tborder: 2px solid;\r\n\tborder-color: rgb(52, 58, 64);\r\n}\r\n"
  },
  {
    "path": "frontend/svelte.config.js",
    "content": "import adapter_static from \"@sveltejs/adapter-static\"; // https://github.com/sveltejs/kit/tree/master/packages/adapter-static\r\n\r\nexport default { // https://kit.svelte.dev/docs/configuration\r\n\textensions: [\r\n\t\t\".svelte\"\r\n\t],\r\n\tkit: {\r\n\t\tadapter: adapter_static({ // an adapter is required to build for prod. see https://kit.svelte.dev/docs/adapters\r\n\t\t\tfallback: true\r\n\t\t}),\r\n\t\tfiles: {\r\n\t\t\ttemplate: \"./source/app.html\",\r\n\t\t\troutes: \"./source/routes/\",\r\n\t\t\thooks: \"./source/hooks.js\",\r\n\t\t\tassets: \"./static/\"\r\n\t\t},\r\n\t\ttrailingSlash: \"never\",\r\n\t\tenv: {\r\n\t\t\tpublicPrefix: \"\"\r\n\t\t}\r\n\t}\r\n};\r\n"
  },
  {
    "path": "frontend/vite.config.js",
    "content": "import * as vite from \"@sveltejs/kit/vite\";\n\nconst frontend = process.cwd();\n\nexport default { // https://vitejs.dev/config\n\tplugins: [\n\t\tvite.sveltekit()\n\t],\n\tresolve: {\n\t\talias: {\n\t\t\tfrontend: frontend // use in import statements within .svelte files\n\t\t}\n\t},\n\tserver: {\n\t\thost: \"0.0.0.0\",\n\t\tport: Number.parseInt(process.env.PORT),\n\t\tstrictPort: true,\n\t\tproxy: {\n\t\t\t\"/backend\": {\n\t\t\t\trewrite: (path) => path.replace(/^(\\/backend)/, \"\"),\n\t\t\t\ttarget: `http://localhost:${Number.parseInt(process.env.PORT)+1}`,\n\t\t\t\tsecure: false,\n\t\t\t\tchangeOrigin: true,\n\t\t\t\tws: true\n\t\t\t}\n\t\t},\n\t\tfs: {\n\t\t\tstrict: true,\n\t\t\tallow: [\n\t\t\t\tfrontend\n\t\t\t]\n\t\t}\n\t}\n};\n"
  },
  {
    "path": "run.sh",
    "content": "#!/bin/sh\n\nif [ \"$1\" = \"dev\" ]; then\n\tif [ \"$2\" = \"audit\" ]; then\n\t\t(cd ./backend/ && npm audit)\n\t\tcd ./frontend/ && npm audit\n\t\treturn\n\telif [ \"$2\" = \"outdated\" ]; then\n\t\t(cd ./backend/ && npm outdated)\n\t\tcd ./frontend/ && npm outdated\n\t\treturn\n\telif [ \"$2\" = \"build\" ]; then\n\t\t(cd ./backend/ && npm install)\n\t\tcd ./frontend/ && npm install && npm run build\n\t\treturn\n\telif [ \"$2\" = \"up\" ]; then\n\t\tconcurrently --names \"backend,frontend\" --prefix \"{name}:\" --prefix-colors \"#f2caff,#61f2f2\" \"cd ./backend/ && npm run dev\" \"wait-for-it 0.0.0.0:1301 -t 0 && cd ./frontend/ && npm run dev\"\n\t\treturn\n\tfi\nelif [ \"$1\" = \"prod\" ]; then\n\tif [ \"$2\" = \"build\" ]; then\n\t\t(cd ./backend/ && npm ci)\n\t\tcd ./frontend/ && npm ci && npm run build\n\t\treturn\n\telif [ \"$2\" = \"up\" ]; then\n\t\tcd ./backend/ && npm run prod_start\n\t\treturn\n\telif [ \"$2\" = \"down\" ]; then\n\t\tcd ./backend/ && npm run prod_stop\n\t\treturn\n\telif [ \"$2\" = \"update\" ]; then\n\t\tsh ./run.sh prod down\n\t\tgit pull\n\t\tsh ./run.sh prod build\n\t\tsh ./run.sh prod up\n\t\treturn\n\tfi\nfi\n"
  }
]