aboutsummaryrefslogtreecommitdiff
path: root/units/ib_hash.zsh
blob: e75c95d8ed14165f7bd4eb7cd79b325885fa2815 (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
# Copyright (C) 2024-2026 Maria Lisina
# Copyright (C) 2024-2026 Danil Lisin
# SPDX-License-Identifier: Apache-2.0

rm -f "${ib_post}"
ib_mode="p"

source "${units}/ib_config.zsh"
source "${units}/ib_authconfig.zsh"

if [[ -z "${ib_data_url}" ]]
then
    exit
fi

ib_query="md5:${ib_post_md5}"

ib_hash="$(sha1sum <<< "${user_id}${ib_board}${ib_query}" | cut -d ' ' -f 1)"
ib_file="${cache}/${ib_hash}.json"

until mkdir "${cache}/${ib_hash}.lock"
do
    sleep 1
done

source "${units}/ib_file.zsh"

if [[ -n "${output_text}" ]]
then
    rmdir "${cache}/${ib_hash}.lock"
    exit
fi

if [[ -z "${output_text}" ]]
then
    ib_id="$(jq -r ".${ib_iarray}[0].${ib_iid}" "${ib_file}")"

    if ! [[ -f "${ib_sample}" ]]
    then
        ib_file_size="$(jq -r ".${ib_iarray}[0].${ib_isize}" "${ib_file}")"
        ib_file_url="$(jq -r ".${ib_iarray}[0].${ib_ifile}" "${ib_file}")"
        ib_sample_url="$(jq -r ".${ib_iarray}[0].${ib_isample}" "${ib_file}")"
        ib_preview_url="$(jq -r ".${ib_iarray}[0].${ib_ipreview}" "${ib_file}")"

        source "${units}/ib_meta.zsh"

        printf "%s\n" "${ib_sample_url}" > "${ib_sample}"
    fi

    printf "%s\n" "${ib_id}" > "${ib_post}"
fi

rmdir "${cache}/${ib_hash}.lock"