{% extends 'components/shell.html' %}

{% from 'components/links.html' import email_link %}
{% from 'components/tooltip.html' import register_message %}

{% block title %}
  <title>Import paywall posts/comments/DMs to {{ g.site_name }}.</title>
{% endblock title %}

{% block content %}
  <section class="page site-section site-section--importer" id="page">
    <h1 class="site-section__heading">Import from paysite</h1>
    {% include "components/importer_states.html" %}
    <form
      id="import-list"
      class="form form--bigger"
      action="/api/v1/importer/submit"
      enctype="application/x-www-form-urlencoded"
      method="POST"
    >
      <div class="form__section">
        <label for="service" class="form__label">Paysite:</label>
        <select id="service" class="form__select" name="service">
          {% for entry in g.paysite_list %}
            {% set paysite = g.paysites[entry] %}
            <option
              class="form__option"
              value="{{ entry }}"
              {{ "selected" if loop.first }}
            >
              {{ paysite.title }}
            </option>
          {% endfor %}
        </select>
      </div>

      <div class="form__section">
        <label class="form__label" for="session-key">
          Session key:
        </label>
        <input
          id="session-key"
          class="form__input"
          type="text"
          name="session_key"
          autocomplete="off"
          autocorrect="off"
          autocapitalize="off"
          spellcheck="false"
          maxlength="1024"
          required
        >

        <small class="form__subtitle other__notes">
          <a href="/importer/tutorial">Learn how to get your session key.</a>
        </small>
        <small class="form__subtitle fansly__notes" hidden>
            Session key.<br>
            On desktop/mobile right click copy the link of this
            <a href="javascript:prompt('Fansly Token', btoa(JSON.stringify({...JSON.parse(localStorage?.session_active_session),device:localStorage?.device_device_id})))">URL</a>
            then on the Fansly webpage enter <span style="color: white; font-weight: bold;">javascript:</span> into your browser url bar and then paste the previously copied string. This will output a result that is your session key<br><br>
            Alternative method: <br>
            Copy the code string below and post this into the browser console. (Open with keyboard F12 or right click > Inspect Element)<br>
            Code: <code style="color: #b5b5b5; user-select: all;">btoa(JSON.stringify({...JSON.parse(localStorage?.session_active_session||'{}'),device:localStorage?.device_device_id}))</code>
        </small>
        <small class="form__subtitle onlyfans__notes" hidden>Session key. Can be found in Cookies -> sess.</small>
        <small class="form__subtitle fanbox__notes" hidden>On Fanbox page, Press F12 -> "Application" tab (check >> if its hidden) -> Storage: Cookies -> fanbox.cc -> FANBOXSESSID value <br> <a href="/importer/tutorial_fanbox">Detailed steps in how to get your fanbox session ID.</a></small>
        <small class="form__subtitle candfans__notes" hidden>On CandFans page, Press F12 -> "Application" tab (check >> if its hidden) -> Storage: Cookies -> candfans.jp -> secure_candfans_session value. <br> <a href="/importer/tutorial">Detailed steps.</a> </small>
      </div>
      <div id="onlyfans-section" class="form__section--hidden" >
        <div class="form__section">
          <input
            id="auth-id"
            class="form__input"
            type="text"
            name="auth_id"
            placeholder="User ID"
            autocomplete="off"
            autocorrect="off"
            autocapitalize="off"
            spellcheck="false"
            maxlength="1024"
            pattern="[0-9]{3,12}"
            required
          >
          <small class="form__subtitle">Your user ID. Can be found in Cookies -> auth_id.</small>
        </div>
        <div class="form__section">

          <input
            id="x-bc"
            class="form__input"
            type="text"
            name="x-bc"
            placeholder="BC Token"
            autocomplete="off"
            autocorrect="off"
            autocapitalize="off"
            spellcheck="false"
            maxlength="1024"
            pattern="[0-9a-f]{30,50}"
            required
          >
          <small class="form__subtitle">
            BC token. Can be found in Local Storage -> bcTokenSha, or the headers of an XHR request -> x-bc.<br>
            Paste this on the console  <code style="color: #b5b5b5; user-select: all;">localStorage.bcTokenSha</code>
          </small>
          
        </div>

        <div class="form__section">

          <label for="service" class="form__label">User Agent:</label>
          <input
            id="user-agent"
            class="form__input"
            type="text"
            name="user_agent"
            placeholder="User Agent"
            autocomplete="off"
            autocorrect="off"
            autocapitalize="off"
            spellcheck="false"
            minlength="10"
            maxlength="1024"
            required
          >
          <small class="form__subtitle">This needs to be set to the <a
            href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent" target="_blank">User-Agent</a>
            of the last device that logged into your OnlyFans account; leave it as the default value if you are on it
            right now.</small>
        </div>

      </div>

      <div id="discord-section" class="form__section form__section--hidden">
        <label for="channel_ids" class="form__label">
          Discord channel IDs:
        </label>
        <input
          type="text"
          class="form__input"
          id="channel_ids"
          name="channel_ids"
          autocomplete="off"
          autocorrect="off"
          autocapitalize="off"
          spellcheck="false"
        >
        <small class="form__subtitle">
          comma separated, no spaces
        </small>
      </div>

      <div id="consent" class="form__section form__section--checkbox">
        <input
          class="form__input"
          type="checkbox"
          checked="checked"
          id="save-session-key"
          name="save_session_key"
          value="1"
        />
        <label class="form__label" for="save-session-key">
          Allow administrator to use my session for debugging
          <br>
          <small class="form__subtitle">
            Contributed debugging keys are encrypted using a strong RSA 4096 key that only the administrator can
            decipher.
          </small>
        </label>
      </div>

      <div id="auto-import-consent" class="form__section form__section--checkbox">
        <input
          class="form__input"
          type="checkbox"
          checked="checked"
          id="auto_import"
          name="auto_import"
          value="1"
        >
        <label class="form__label" for="auto_import">
          Allow the importer to save my session key for auto-import
          <br>
          <small class="form__subtitle">
            If enabled, new posts will automatically be imported every 24 hours without manual intervention. Direct
            message importing still requires manual import. See notes below for security information.
          </small>
        </label>
      </div>

      <div id="dm-consent" class="form__section  form__section--hidden form__section--checkbox">
        <input
          class="form__input"
          type="checkbox"
          id="save-dms"
          name="save_dms"
          value="1"
        >
        <label class="form__label" for="save-dms">
          Allow the importer to access your direct messages
          <br>
          <small class="form__subtitle">
            You will be able to manually approve or discard messages before they are publicly displayed.
          </small>
        </label>
      </div>

      <div id="fanbox-test-consent" class="form__section  form__section--hidden form__section--checkbox">
        <input
          class="form__input"
          type="checkbox"
          id="fanbox-test-consent"
          name="fanbox-test-consent"
          value='0'
        >
        <label class="form__label" for="fanbox-test-consent">
          I agree that this importer is in its testing phase, and that there may be risks involved.
          <br>
          <small class="form__subtitle">
            <a href="/fanboximports">Check details here</a>
          </small>
        </label>
      </div>

      <div class="form__section">
        <button
          class="form__button form__button--submit"
          type="submit"
        >
          Submit key
        </button>
      </div>

    </form>
    <h2 class="site-section__subheading">Important information</h2>
    <p>
      Your session key is used to scrape paid posts from your feed. After downloading missing posts, the key is
      immediately discarded and never stored without permission.
    </p>
    {% if "fantia" in g.paysite_list %}
      <h3>Fantia</h3>
      <ul>
        <li>At least one paid content must be unlocked for the post to be imported. <i>Free posts cannot be archived at
          this time.</i></li>
        <li>In order to download post contents accurately, the importer will automatically enable adult-viewing mode for
          duration of the import if you have it turned off. <b>Do not change back to general-viewing during imports.</b>
        </li>
      </ul>
    {% endif %}
    <h3>Auto-import</h3>
    <p>
      The auto-import feature allows users to give {{ g.site_name }} permission to automatically detect and retrieve new
      posts and creators by storing session keys long-term, without need for manual key submission. All keys are
      encrypted using a strong RSA 4096 key. When the administrators start a new autoimport round, a computer outside of
      {{ g.site_name }}'s infrastucture sends the private key to the backend, allowing it to decrypt all working keys
      and start import tasks. Even if {{ g.site_name }}'s private database were to somehow be compromised, your tokens
      would remain anonymous and secure.<br>
      If you are logged into {{ g.site_name }}, any key you submit with autoimport enabled can be managed under the <b>Keys</b>
      section of your <b>[Account]</b> tab in the header. There, you will be able to view import logs or revoke access.
      <i>Please note that anonymously-submitted keys cannot be managed.</i>
    </p>
  </section>
{% endblock content %}

{% block components %}
  {{ register_message("DM import") }}
{% endblock components %}
