1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-14 01:34:47 +08:00

feat(website): Optimize website expiration time setting (#8061)

This commit is contained in:
zhengkunwang 2025-03-04 17:58:57 +08:00 committed by GitHub
parent f71ff7d80c
commit 9ee3832cda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 30 additions and 8 deletions

View File

@ -518,6 +518,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
runtime.CodeDir = req.CodeDir
runtime.Port = strings.Join(hostPorts, ",")
runtime.Status = constant.StatusReCreating
runtime.ContainerName = req.Params["CONTAINER_NAME"].(string)
_ = runtimeRepo.Save(runtime)
go reCreateRuntime(runtime)
}

View File

@ -259,7 +259,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
primaryDomain = fmt.Sprintf("%s:%v", domains[0].Domain, domains[0].Port)
}
defaultDate, _ := time.Parse(constant.DateLayout, constant.DefaultDate)
defaultDate, _ := time.Parse(constant.DateLayout, constant.WebsiteDefaultExpireDate)
website := &model.Website{
PrimaryDomain: primaryDomain,
Type: create.Type,

View File

@ -23,10 +23,11 @@ const (
TimeOut20s = 20
TimeOut5m = 300
DateLayout = "2006-01-02" // or use time.DateOnly while go version >= 1.20
DefaultDate = "1970-01-01"
DateTimeLayout = "2006-01-02 15:04:05" // or use time.DateTime while go version >= 1.20
DateTimeSlimLayout = "20060102150405"
DateLayout = "2006-01-02" // or use time.DateOnly while go version >= 1.20
DefaultDate = "1970-01-01"
DateTimeLayout = "2006-01-02 15:04:05" // or use time.DateTime while go version >= 1.20
DateTimeSlimLayout = "20060102150405"
WebsiteDefaultExpireDate = "9999-12-31"
)
const (

View File

@ -27,6 +27,7 @@ func InitAgentDB() {
migrations.AddOllamaModel,
migrations.UpdateSettingStatus,
migrations.InitDefault,
migrations.UpdateWebsiteExpireDate,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)

View File

@ -3,6 +3,7 @@ package migrations
import (
"fmt"
"path"
"time"
"github.com/1Panel-dev/1Panel/agent/app/dto/request"
"github.com/1Panel-dev/1Panel/agent/app/model"
@ -296,3 +297,17 @@ var InitDefault = &gormigrate.Migration{
return nil
},
}
var UpdateWebsiteExpireDate = &gormigrate.Migration{
ID: "20250304-update-website",
Migrate: func(tx *gorm.DB) error {
targetDate := time.Date(9999, 12, 31, 0, 0, 0, 0, time.UTC)
if err := tx.Model(&model.Website{}).
Where("expire_date = ?", time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)).
Update("expire_date", targetDate).Error; err != nil {
return err
}
return nil
},
}

View File

@ -272,7 +272,7 @@ const shortcuts = [
{
text: useI18n().t('website.ever'),
value: () => {
return new Date('1970-01-01');
return new Date('9999-12-31');
},
},
{
@ -379,7 +379,7 @@ const openConfig = (id: number) => {
const isEver = (time: string) => {
const expireDate = new Date(time);
return expireDate < new Date('1970-01-02');
return expireDate > new Date('9999-12-30');
};
const isBeforeNow = (time: string) => {
@ -415,10 +415,14 @@ const setdateRefs = (ref: any) => {
};
const initDatePicker = (row: any) => {
if (dataRef.value == undefined && row.oldExpireDate == undefined && isBeforeNow(row.expireDate)) {
if (
(dataRef.value == undefined && row.oldExpireDate == undefined && isBeforeNow(row.expireDate)) ||
isEver(row.expireDate)
) {
row.oldExpireDate = row.expireDate;
const date = new Date().toLocaleDateString();
row.expireDate = date;
return;
}
};