File size: 1,475 Bytes
b628664
 
9fd8477
 
 
 
 
b628664
 
 
 
 
 
 
 
 
 
 
9fd8477
 
 
db9bd2d
f40f303
 
9fd8477
 
 
 
 
 
 
 
 
 
b73edb4
 
 
db9bd2d
f40f303
 
9fd8477
 
 
 
 
 
 
 
 
 
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
import { handler } from './build/handler.js';
import express from 'express';
import cron from 'node-cron';
import fetch from 'node-fetch';
import dotenv from 'dotenv';

dotenv.config();

const app = express();

// Serve your "data/assets" folder
app.use(express.static('data/assets'))

// let SvelteKit handle everything else, including serving prerendered pages and static assets
app.use(handler);

app.listen(3000, () => {
    console.log('listening on port 3000');
});

cron.schedule("0 * * * *", async () => {
    console.log('Scraping models')
    const first_space_host = process.env.SPACE_HOST?.split(',')[0] ?? process.env.SPACE_HOST
    const request = await fetch(`https://${first_space_host}/api/scrap-models`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'x-hf-token': process.env.SECRET_HF_TOKEN
        },
    });
    const response = await request.json();
    console.info(response?.message)
});

cron.schedule(
    "0 0 * * *"
    , async () => {
    console.log('Updating models')
    const first_space_host = process.env.SPACE_HOST?.split(',')[0] ?? process.env.SPACE_HOST
    const request = await fetch(`http://${first_space_host}/api/models`, {
        method: 'PATCH',
        headers: {
            'Content-Type': 'application/json',
            'x-hf-token': process.env.SECRET_HF_TOKEN
        },
    });
    const response = await request.json();
    console.info(response?.message)
});