feat(web): add image_hosting

This commit is contained in:
Baoshuo Ren 2022-10-12 20:35:23 +08:00
parent 0d0b8b0ba7
commit ec80c669d1
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
12 changed files with 107 additions and 0 deletions

View File

@ -815,6 +815,7 @@ CREATE TABLE `user_info` (
`motto` varchar(200) NOT NULL,
`last_login` timestamp NOT NULL DEFAULT 0,
`last_visited` timestamp NOT NULL DEFAULT 0,
`images_size_limit` int(11) UNSIGNED NOT NULL DEFAULT 104857600, /* 100 MiB */
PRIMARY KEY (`username`),
KEY `ac_num` (`ac_num`,`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
@ -829,6 +830,35 @@ LOCK TABLES `user_info` WRITE;
/*!40000 ALTER TABLE `user_info` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `users_images`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `users_images` (
`id` varchar(30) NOT NULL,
`username` varchar(20) NOT NULL,
`width` int(11) NOT NULL,
`height` int(11) NOT NULL,
`upload_time` datetime NOT NULL,
`size` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `username` (`username`),
KEY `upload_time` (`upload_time`),
KEY `size` (`size`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `users_images`
--
LOCK TABLES `users_images` WRITE;
/*!40000 ALTER TABLE `users_images` DISABLE KEYS */;
/*!40000 ALTER TABLE `users_images` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `user_msg`
--

View File

@ -0,0 +1,6 @@
<?php
requirePHPLib('form');
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin();
}

View File

@ -0,0 +1,21 @@
<?php
requirePHPLib('form');
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
redirectToLogin();
}
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
become403Page();
}
$REQUIRE_LIB['bootstrap5'] = '';
?>
<?php echoUOJPageHeader(UOJLocale::get('image hosting')) ?>
<h1 class="h2">
<?= UOJLocale::get('image hosting') ?>
</h1>
<?php echoUOJPageFooter() ?>

View File

@ -100,4 +100,6 @@ return [
'last active at' => 'Last active at',
'online' => 'Online',
'offline' => 'Offline',
'apps' => 'Apps',
'image hosting' => 'Image Hosting',
];

View File

@ -100,4 +100,6 @@ return [
'online' => '在线',
'offline' => '离线',
'last active at' => '最后活动于',
'apps' => '应用',
'image hosting' => '图床',
];

View File

@ -5,6 +5,7 @@ Route::pattern('id', '[1-9][0-9]{0,9}');
Route::pattern('contest_id', '[1-9][0-9]{0,9}');
Route::pattern('tab', '\S{1,20}');
Route::pattern('rand_str_id', '[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]{20}');
Route::pattern('image_name', '[0123456789abcdefghijklmnopqrstuvwxyz]{7}');
Route::pattern('upgrade_name', '[a-zA-Z0-9_]{1,50}');
Route::group([
@ -78,6 +79,10 @@ Route::group([
Route::any('/download.php', '/download.php');
Route::any('/click-zan', '/click_zan.php');
// Image Hosting
Route::any('/image-hosting', '/image_hosting/index.php');
Route::get('/image-hosting/{image_name}.png', '/image_hosting/get_image.php');
}
);

View File

View File

@ -0,0 +1 @@
ref: https://github.com/renbaoshuo/S2OJ/issues/4

View File

@ -0,0 +1,2 @@
ALTER TABLE `user_info` DROP COLUMN IF EXISTS `images_size_limit`;
DROP TABLE IF EXISTS `users_images`;

View File

@ -0,0 +1,21 @@
ALTER TABLE `user_info` ADD COLUMN `images_size_limit` int(11) UNSIGNED NOT NULL DEFAULT 104857600 /* 100 MiB */;
--
-- Table structure for table `users_images`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE IF NOT EXISTS `users_images` (
`id` varchar(30) NOT NULL,
`username` varchar(20) NOT NULL,
`width` int(11) NOT NULL,
`height` int(11) NOT NULL,
`upload_time` datetime NOT NULL,
`size` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `username` (`username`),
KEY `upload_time` (`upload_time`),
KEY `size` (`size`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

View File

@ -103,6 +103,22 @@ mb-4" role="navigation">
<?= UOJLocale::get('blogs') ?>
</a>
</li>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-grid-3x3-gap"></i>
<?= UOJLocale::get('apps') ?>
</a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="<?= HTML::url('/image-hosting') ?>">
<i class="bi bi-images"></i>
<?= UOJLocale::get('image hosting') ?>
</a>
</li>
</ul>
</li>
<?php endif ?>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/faq') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>

View File

@ -89,6 +89,7 @@ initProgress(){
service apache2 restart
mkdir -p /opt/uoj/web/app/storage/submission
mkdir -p /opt/uoj/web/app/storage/tmp
mkdir -p /opt/uoj/web/app/storage/image_hosting
chmod -R 777 /opt/uoj/web/app/storage
#Using cli upgrade to latest
php7.4 /var/www/uoj/app/cli.php upgrade:latest