Commit 596810c8 authored by chenhan wang's avatar chenhan wang
Browse files

本地调试2,0

parent df2a78f0
...@@ -3,7 +3,7 @@ package model ...@@ -3,7 +3,7 @@ package model
import ( import (
//"fmt" //"fmt"
"time" "time"
// "math/rand" // "math/rand"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/viper" "github.com/spf13/viper"
...@@ -26,7 +26,7 @@ func Init() { ...@@ -26,7 +26,7 @@ func Init() {
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
err = DB.AutoMigrate(&Sid{},&Url{}) err = DB.AutoMigrate(&Sid{}, &Url{})
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
...@@ -52,7 +52,7 @@ func ConnectDatabase() { ...@@ -52,7 +52,7 @@ func ConnectDatabase() {
} }
// Backcheck content through link // Backcheck content through link
//通过链接反查内容 // 通过链接反查内容
func Findlink(_url string) string { func Findlink(_url string) string {
var p Content var p Content
err := DB.First(&p, "Url1 = ?", _url) err := DB.First(&p, "Url1 = ?", _url)
...@@ -63,41 +63,41 @@ func Findlink(_url string) string { ...@@ -63,41 +63,41 @@ func Findlink(_url string) string {
} }
// save text information // save text information
//保存文本和文件信息 // 保存文本和文件信息
func Savetext(_Route string, _Time uint, _Passwd string,_Time1 time.Time,_url string) { func Savetext(_Route string, _Time uint, _Passwd string, _Time1 time.Time, _url string) {
id1++ id1++
p := Content{ p := Content{
ID : id1, ID: id1,
Route: _Route, Route: _Route,
Time: _Time, Time: _Time,
Passwd: _Passwd, Passwd: _Passwd,
Date: time.Now(), Date: time.Now(),
Time1: _Time1, Time1: _Time1,
Time2: 0, Time2: 0,
Url1: _url, Url1: _url,
} }
DB.Create(&p) DB.Create(&p)
} }
// Check whether the number of visits exceeds the threshold and the time limit // Check whether the number of visits exceeds the threshold and the time limit
//检查是否超过总访问次数和截止时间 // 检查是否超过总访问次数和截止时间
func Checkt(_Route string) { func Checkt(_Route string) {
var p Content var p Content
err := DB.First(&p, "Route = ?",_Route) err := DB.First(&p, "Route = ?", _Route)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
t := time.Now() t := time.Now()
p.Time2++ p.Time2++
if p.Time2 > p.Time||t.After(p.Time1) { if p.Time2 > p.Time || t.After(p.Time1) {
DB.Delete(&p) DB.Delete(&p)
} }
} }
//查找sessionid和url是否关联 // 查找sessionid和url是否关联
func Find(sid string,_url string) bool { func Find(sid string, _url string) bool {
var s Sid var s Sid
err1 := DB.First(&s, "S = ?",sid).Error err1 := DB.First(&s, "S = ?", sid).Error
//fmt.Println(url.Url1,url.ID,"\n") //fmt.Println(url.Url1,url.ID,"\n")
if err1 != nil { if err1 != nil {
return false return false
...@@ -106,7 +106,7 @@ func Find(sid string,_url string) bool { ...@@ -106,7 +106,7 @@ func Find(sid string,_url string) bool {
DB.Model(&s).Association("Url1").Find(&Urls) DB.Model(&s).Association("Url1").Find(&Urls)
for _, value := range Urls { for _, value := range Urls {
if value.Url1 == _url { if value.Url1 == _url {
return true return true
} }
} }
return false return false
...@@ -124,30 +124,30 @@ func randStr(n int) string { ...@@ -124,30 +124,30 @@ func randStr(n int) string {
return string(b) return string(b)
}*/ }*/
//新建用户 // 新建用户
func Createuser(_User Users) { func Createuser(_User Users) {
//_User.SessionId=randStr(8) //_User.SessionId=randStr(8)
DB.Create(&_User) DB.Create(&_User)
} }
//新建链接 // 新建链接
func Createlink(sid string , _passwd string , _url string) bool { func Createlink(sid string, _passwd string, _url string) bool {
var p Content var p Content
DB.First(&p, "Url1 = ?", _url) DB.First(&p, "Url1 = ?", _url)
if p.Passwd == _passwd { if p.Passwd == _passwd {
var p1 Sid var p1 Sid
err := DB.First(&p1, "S = ?", sid).Error err := DB.First(&p1, "S = ?", sid).Error
if err !=nil { if err != nil {
sid1 := Sid{ sid1 := Sid{
S:sid, S: sid,
Url1: []Url{ Url1: []Url{
{ Url1: _url}, {Url1: _url},
}, },
} }
DB.Create(&sid1) DB.Create(&sid1)
} else { } else {
DB.Model(&p1).Association("Url1").Append(&Url{Url1:_url}) DB.Model(&p1).Association("Url1").Append(&Url{Url1: _url})
} }
return true return true
} }
return false return false
......
This source diff could not be displayed because it is too large. You can view the blob instead.
create database pastebin;
create user 'rootp'@'localhost' identified by 'pastebingroup1';
grant all privileges on pastebin.* to 'rootp'@'localhost';
use pastebin;
-- MySQL dump 10.13 Distrib 8.0.31, for Win64 (x86_64)
--
-- Host: localhost Database: pastebin
-- ------------------------------------------------------
-- Server version 8.0.31
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `contents`
--
DROP TABLE IF EXISTS `contents`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `contents` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`route` longtext,
`time` bigint unsigned DEFAULT NULL,
`passwd` longtext,
`date` datetime(3) DEFAULT NULL,
`size` bigint unsigned DEFAULT NULL,
`time1` datetime(3) DEFAULT NULL,
`time2` bigint unsigned DEFAULT NULL,
`url1` longtext,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `contents`
--
LOCK TABLES `contents` WRITE;
/*!40000 ALTER TABLE `contents` DISABLE KEYS */;
/*!40000 ALTER TABLE `contents` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `sid_urls`
--
DROP TABLE IF EXISTS `sid_urls`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `sid_urls` (
`sid_id` bigint unsigned NOT NULL,
`url_id` bigint unsigned NOT NULL,
PRIMARY KEY (`sid_id`,`url_id`),
KEY `fk_sid_urls_url` (`url_id`),
CONSTRAINT `fk_sid_urls_sid` FOREIGN KEY (`sid_id`) REFERENCES `sids` (`id`),
CONSTRAINT `fk_sid_urls_url` FOREIGN KEY (`url_id`) REFERENCES `urls` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `sid_urls`
--
LOCK TABLES `sid_urls` WRITE;
/*!40000 ALTER TABLE `sid_urls` DISABLE KEYS */;
/*!40000 ALTER TABLE `sid_urls` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `sids`
--
DROP TABLE IF EXISTS `sids`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `sids` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime(3) DEFAULT NULL,
`updated_at` datetime(3) DEFAULT NULL,
`deleted_at` datetime(3) DEFAULT NULL,
`s` longtext,
PRIMARY KEY (`id`),
KEY `idx_sids_deleted_at` (`deleted_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `sids`
--
LOCK TABLES `sids` WRITE;
/*!40000 ALTER TABLE `sids` DISABLE KEYS */;
/*!40000 ALTER TABLE `sids` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `urls`
--
DROP TABLE IF EXISTS `urls`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `urls` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime(3) DEFAULT NULL,
`updated_at` datetime(3) DEFAULT NULL,
`deleted_at` datetime(3) DEFAULT NULL,
`url1` longtext,
PRIMARY KEY (`id`),
KEY `idx_urls_deleted_at` (`deleted_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `urls`
--
LOCK TABLES `urls` WRITE;
/*!40000 ALTER TABLE `urls` DISABLE KEYS */;
/*!40000 ALTER TABLE `urls` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `users`
--
DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `users` (
`session_id` longtext,
`username` longtext,
`passwd` longtext,
`name` longtext,
`size` bigint unsigned DEFAULT NULL,
`route` longtext
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `users`
--
LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2023-01-17 22:07:33
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment