summaryrefslogtreecommitdiff
path: root/public/uploaders.php
blob: 57cf8b44f501ffa8046a324a93470ca23eee41f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/../config.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/partials.php';

$file_types = [];

foreach (FILE_ACCEPTED_MIME_TYPES as $k => $v) {
    $type = ucfirst(explode('/', $v)[0]);
    if (!array_key_exists($type, $file_types)) {
        $file_types[$type] = [];
    }

    if (!in_array($k, $file_types[$type])) {
        array_push($file_types[$type], $k);
    }
}
?>
<html>

<head>
    <title>Uploaders - <?= INSTANCE_NAME ?></title>
    <link rel="stylesheet" href="/static/style.css">
    <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon">
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>

<body>
    <main>
        <?php html_big_navbar() ?>

        <section class="column gap-16">
            <div>
                <h1>File Uploaders</h1>
                <p>Configure your software to work with <?= INSTANCE_NAME ?></p>
            </div>

            <!-- SOFTWARE -->
            <div class="row gap-8">
                <!-- SHAREX -->
                <section class="column">
                    <div class="column">
                        <h2>ShareX</h2>
                        <p class="small-font">(Destinations &rarr; Custom uploader settings &rarr; New)</p>
                    </div>
                    <table class="vertical">
                        <tr>
                            <th>Name:</th>
                            <td><code><?= INSTANCE_NAME ?></code></td>
                        </tr>
                        <tr>
                            <th>Request URL:</th>
                            <td><code class="copy"><?= INSTANCE_URL ?>/upload.php</code></td>
                        </tr>
                        <tr>
                            <th>Destination type:</th>
                            <td><code>Image uploader</code></td>
                        </tr>
                        <tr>
                            <th>Method:</th>
                            <td><code>POST</code></td>
                        </tr>
                        <tr>
                            <th>Body:</th>
                            <td><code>Form data (multipart/form-data)</code></td>
                        </tr>
                        <tr>
                            <th>Headers:</th>
                            <td><code>Accept: application/json</code></td>
                        </tr>
                        <tr>
                            <th>File form name:</th>
                            <td><code class="copy">file</code></td>
                        </tr>
                        <tr>
                            <th>URL:</th>
                            <td><code class="copy">{json:data.urls.download_url}</code></td>
                        </tr>
                    </table>
                    <p>Then, select it via <b>Destinations &rarr; Image uploader &rarr; Custom image
                            uploader</b></p>
                </section>

                <!-- CHATTERINO -->
                <section class="column">
                    <div class="column">
                        <h2>Chatterino</h2>
                        <p class="small-font">(Settings &rarr; External tools &rarr; Image Uploader)</p>
                    </div>
                    <table class="vertical">
                        <tr>
                            <th>Request URL:</th>
                            <td><code class="copy"><?= INSTANCE_URL ?>/upload.php</code></td>
                        </tr>
                        <tr>
                            <th>Form field:</th>
                            <td><code class="copy">file</code></td>
                        </tr>
                        <tr>
                            <th>Extra headers:</th>
                            <td><code class="copy">Accept: application/json</code></td>
                        </tr>
                        <tr>
                            <th>Image link:</th>
                            <td><code class="copy">{data.urls.download_url}</code></td>
                        </tr>
                    </table>
                </section>
            </div>

            <!-- API -->
            <section class="column gap-16">
                <h2>API</h2>
                <div class="column">
                    <h3>Endpoint</h3>
                    <hr>
                    <p><code>POST <span class="copy"><?= INSTANCE_URL ?>/upload.php</span></code></p>
                </div>

                <div>
                    <h3>Request Format</h3>
                    <hr>
                    <table class="vertical">
                        <tr>
                            <th>Method:</th>
                            <td><code>POST</code></td>
                        </tr>
                        <tr>
                            <th>Content-Type:</th>
                            <td><code>multipart/form-data</code></td>
                        </tr>
                        <tr>
                            <th>Headers:</th>
                            <td><code>Accept: application/json</code></td>
                        </tr>
                        <tr>
                            <th>File field:</th>
                            <td><code>file</code></td>
                        </tr>
                        <tr>
                            <th>Max file size:</th>
                            <td><code><?= get_cfg_var("upload_max_filesize") ?></code></td>
                        </tr>
                    </table>
                </div>

                <div class="column" id="supported-file-extensions">
                    <h3>Supported file extensions</h3>
                    <hr>
                    <table class="vertical">
                        <?php foreach ($file_types as $type => $exts): ?>
                            <tr>
                                <th><?= $type ?>:</th>
                                <td style="text-align: justify"><?= implode(' ', $exts) ?></td>
                            </tr>
                        <?php endforeach; ?>
                    </table>
                </div>
            </section>
        </section>
    </main>
</body>

<script>
    const copyButtons = document.querySelectorAll(".copy");
    for (const copyButton of copyButtons) {
        const content = copyButton.innerHTML;
        const button = document.createElement("button");

        button.innerHTML = '<img src="/static/img/icons/paste_plain.png" alt="Copy" />';
        button.addEventListener("click", () => {
            navigator.clipboard.writeText(content);
        });

        copyButton.parentElement.appendChild(button);
    }
</script>

</html>