File size: 2,638 Bytes
518bc25
 
 
 
 
 
 
 
 
 
7e54ea0
518bc25
 
 
 
 
 
 
 
 
 
 
7e54ea0
518bc25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7e54ea0
518bc25
a56e65f
518bc25
 
 
 
 
 
 
 
a56e65f
 
518bc25
 
 
 
 
 
59a1fb9
 
 
518bc25
 
 
 
 
 
 
7e54ea0
518bc25
 
7e54ea0
518bc25
 
954ec7f
518bc25
 
59a1fb9
518bc25
 
 
954ec7f
518bc25
 
59a1fb9
518bc25
7e54ea0
518bc25
 
 
 
 
 
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
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { logger } from './utils/logger';
import { loadConfig } from './utils/config';

const config = loadConfig();
const requestTimeout = config.request_timeout || 30000;

const app = new Hono();

// CORS middleware: Disable all restrictions
app.use(
  '*',
  cors({
    origin: '*',
    allowMethods: ['*'],
    allowHeaders: ['*'],
    exposeHeaders: ['*'],
    maxAge: 86400,
  }),
);

// Request log middleware
app.use('*', async (c, next) => {
  const start = Date.now();
  await next();
  const end = Date.now();
  const responseTime = end - start;

  if (c.req.path.includes('.well-known/appspecific/com.chrome.devtools.json')) return;

  const decodedQuery = Object.entries(c.req.query())
    .map(([key, value]) => `${key}=${decodeURIComponent(value)}`)
    .join('&');

  const fullPath = decodedQuery ? `${c.req.path}?${decodedQuery}` : c.req.path;

  logger.debug(`[${c.req.method}] [${c.res.status}] ${fullPath} - ${responseTime}ms`);
});

app.use('*', async (c, next) => {
  await next();
  c.header('Server', 'THIS SERVER IS POWERED BY PENGUINS');
});

// Base route
app.get('/', (c) => {
  const baseDomain = new URL(c.req.url).host;
  return c.text(
    `Proxy Server for LINE Store API and CDN
by daydreamer-json

This server is powered by penguins uwu (and Hono)

---

Base Domain: ${baseDomain}

Example:
- /api/search?category=sticker&type=ALL&query=koupen&offset=0&limit=1
- /api/download/sticker/zip/18537?device_type=ios&is_static=false&size=2
- /api/download/sticker/single/23214968?device_type=android&is_static=false&size=1
- /api/download/sticker/thumb/18537?device_type=ios
- /api/download/sticker/sound/single/350279022?device_type=ios
- /api/download/sticker/sound/thumb/18537?device_type=ios

More info: /docs`,
    200,
    {
      'Content-Type': 'text/plain',
    },
  );
});

// API route group
const apiRoutes = app.basePath('/api');

// Register routes
import searchRoutes from './routes/search';
import metaRoutes from './routes/meta';
import metaWebRoutes from './routes/metaWeb';
import stickerRoutes from './routes/download/sticker';
import emojiRoutes from './routes/download/emoji';
import docsRoutes from './routes/docs';

apiRoutes.route('/search', searchRoutes);
apiRoutes.route('/meta', metaRoutes);
apiRoutes.route('/meta_web', metaWebRoutes);
apiRoutes.route('/download/sticker', stickerRoutes);
apiRoutes.route('/download/emoji', emojiRoutes);
app.route('/docs', docsRoutes);

// Start server
const port = process.env.PORT || 3000;
logger.info(`Server running on port ${port}`);
Bun.serve({
  port,
  fetch: app.fetch,
});