-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v1.0.5] Merge pull request #21 from KageRyo/develop
Update to v1.0.5
- Loading branch information
Showing
6 changed files
with
53 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2 on 2024-07-30 08:15 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('shortURL', '0005_url_visit_count'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='url', | ||
name='expire_date', | ||
field=models.DateTimeField(blank=True, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
from django.shortcuts import get_object_or_404, redirect | ||
from django.utils import timezone | ||
from django.http import HttpResponse | ||
from .models import Url | ||
|
||
# 將短網址導向原網址的函式 | ||
def redirectShortUrl(request, short_string): | ||
url = get_object_or_404(Url, short_string=short_string) | ||
|
||
# 檢查短網址是否已過期 | ||
if url.expire_date and url.expire_date < timezone.now(): | ||
url.delete() | ||
return HttpResponse("此短網址已過期並已被刪除。", status=404) | ||
|
||
# 更新訪問次數 | ||
url.visit_count += 1 | ||
url.save() | ||
|
||
# 進行重定向 | ||
return redirect(url.orign_url) |