File size: 1,930 Bytes
0070fce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { Octokit } from '@octokit/rest';
import confJson from '../../src-tauri/tauri.conf.json'
import { computed, ref } from 'vue'
import { delay } from 'vue3-ts-util'
import { getVersion } from '@/api'
import { ReturnTypeAsync } from '.'


const octokit = new Octokit();
export const localFeTag = 'v' + confJson.package.version
export const latestCommit = ref<ReturnTypeAsync<typeof getLatestCommit>>()
export const latestTag = ref('')
export const localBeHash = ref('')
export const localBeTag = ref('')

export const version = computed(() => ({
  tag: localBeTag.value || localFeTag,
  hash: localBeHash.value
}))

export const hasNewRelease = computed(() => {
  if (!latestTag.value) {
    return false
  }
  return latestTag.value !== version.value.tag
})



async function getLatestCommit(owner: string, repo: string) {
  try {
    const response = await octokit.repos.listCommits({
      owner,
      repo,
      per_page: 1,
    });
    const latestCommit = response.data[0];
    // console.log('Latest Commit:', latestCommit);
    return latestCommit;
  } catch (error) {
    console.error('Error fetching the latest commit:', error);
  }
}

async function getLatestRelease(owner: string, repo: string) {
  try {
    const response = await octokit.repos.getLatestRelease({
      owner,
      repo,
    });
    const latestRelease = response.data;
    // console.log('Latest Release:', latestRelease);
    return latestRelease;
  } catch (error) {
    console.error('Error fetching the latest release:', error);
  }
}

const owner = 'zanllp';
const repo = 'sd-webui-infinite-image-browsing';

delay(500 + 500 * Math.random()).then(async () => {
  getVersion().then((resp) => {
    localBeTag.value = resp.tag ?? ''
    localBeHash.value = resp.hash ?? ''
  })
  latestCommit.value = await getLatestCommit(owner, repo);
  const release =  await getLatestRelease(owner, repo);
  latestTag.value = release?.tag_name ?? ''
})