forked from retoor/devplacepy
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8ed5b690f |
File diff suppressed because one or more lines are too long
@@ -42,7 +42,6 @@ def init_db():
|
|||||||
_index(db, "posts", "idx_posts_created_at", ["created_at"])
|
_index(db, "posts", "idx_posts_created_at", ["created_at"])
|
||||||
_index(db, "posts", "idx_posts_topic", ["topic"])
|
_index(db, "posts", "idx_posts_topic", ["topic"])
|
||||||
_index(db, "posts", "idx_posts_slug", ["slug"])
|
_index(db, "posts", "idx_posts_slug", ["slug"])
|
||||||
_index(db, "posts", "idx_posts_project_uid", ["project_uid"])
|
|
||||||
if "posts" in tables:
|
if "posts" in tables:
|
||||||
posts_table = get_table("posts")
|
posts_table = get_table("posts")
|
||||||
if not posts_table.has_column("tags"):
|
if not posts_table.has_column("tags"):
|
||||||
|
|||||||
@@ -470,9 +470,19 @@ class SeoRunForm(BaseModel):
|
|||||||
text = value.strip()
|
text = value.strip()
|
||||||
if not text:
|
if not text:
|
||||||
raise ValueError("A URL is required")
|
raise ValueError("A URL is required")
|
||||||
|
if "://" in text:
|
||||||
|
scheme = text.split("://", 1)[0]
|
||||||
|
if scheme not in ("http", "https"):
|
||||||
|
raise ValueError(f"Only http and https URLs are allowed; got '{scheme}://'")
|
||||||
|
else:
|
||||||
|
text = f"https://{text}"
|
||||||
|
if not SEO_URL_PATTERN.match(text):
|
||||||
|
raise ValueError("URL must be a valid http or https source location")
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
SEO_URL_PATTERN = re.compile(r"^https?://[a-zA-Z0-9][\w./:@~^?&#%=;-]*$")
|
||||||
|
|
||||||
ISSLOP_URL_PATTERN = re.compile(r"^(https?://|git://|ssh://|git@)[\w./:@~^-]+$", re.IGNORECASE)
|
ISSLOP_URL_PATTERN = re.compile(r"^(https?://|git://|ssh://|git@)[\w./:@~^-]+$", re.IGNORECASE)
|
||||||
ISSLOP_SINGLE_SLASH_PATTERN = re.compile(r"^(https?|git|ssh):/(?!/)", re.IGNORECASE)
|
ISSLOP_SINGLE_SLASH_PATTERN = re.compile(r"^(https?|git|ssh):/(?!/)", re.IGNORECASE)
|
||||||
ISSLOP_SCHEME_PATTERN = re.compile(r"^[a-z][a-z0-9+.-]*://", re.IGNORECASE)
|
ISSLOP_SCHEME_PATTERN = re.compile(r"^[a-z][a-z0-9+.-]*://", re.IGNORECASE)
|
||||||
|
|||||||
@@ -216,15 +216,6 @@ async def project_detail(request: Request, project_slug: str):
|
|||||||
if parent
|
if parent
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
posts_table = get_table("posts")
|
|
||||||
project_posts = list(
|
|
||||||
posts_table.find(
|
|
||||||
project_uid=project["uid"],
|
|
||||||
deleted_at=None,
|
|
||||||
order_by=["-created_at"],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return respond(
|
return respond(
|
||||||
request,
|
request,
|
||||||
"project_detail.html",
|
"project_detail.html",
|
||||||
@@ -244,7 +235,6 @@ async def project_detail(request: Request, project_slug: str):
|
|||||||
"forked_from": forked_from,
|
"forked_from": forked_from,
|
||||||
"fork_count": count_forks(project["uid"]),
|
"fork_count": count_forks(project["uid"]),
|
||||||
"file_count": count_files(project["uid"]),
|
"file_count": count_files(project["uid"]),
|
||||||
"project_posts": project_posts,
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
model=ProjectDetailOut,
|
model=ProjectDetailOut,
|
||||||
|
|||||||
@@ -163,7 +163,6 @@ class ProjectDetailOut(_Out):
|
|||||||
forked_from: Optional[dict] = None
|
forked_from: Optional[dict] = None
|
||||||
fork_count: int = 0
|
fork_count: int = 0
|
||||||
file_count: int = 0
|
file_count: int = 0
|
||||||
project_posts: list[PostOut] = []
|
|
||||||
|
|
||||||
|
|
||||||
class GistsOut(_Out):
|
class GistsOut(_Out):
|
||||||
|
|||||||
@@ -313,50 +313,3 @@
|
|||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.project-devlog {
|
|
||||||
margin-top: 2rem;
|
|
||||||
padding-top: 1.5rem;
|
|
||||||
border-top: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.devlog-list {
|
|
||||||
list-style: none;
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.devlog-item {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
padding: 0.5rem 0;
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
gap: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.devlog-item:last-child {
|
|
||||||
border-bottom: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.devlog-link {
|
|
||||||
color: var(--text-primary);
|
|
||||||
text-decoration: none;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.devlog-link:hover {
|
|
||||||
color: var(--accent);
|
|
||||||
}
|
|
||||||
|
|
||||||
.devlog-date {
|
|
||||||
font-size: 0.8125rem;
|
|
||||||
color: var(--text-muted);
|
|
||||||
white-space: nowrap;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.devlog-empty {
|
|
||||||
color: var(--text-muted);
|
|
||||||
font-size: 0.875rem;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -170,22 +170,6 @@
|
|||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="project-devlog">
|
|
||||||
<h2 class="project-section-label">Devlog</h2>
|
|
||||||
{% if project_posts %}
|
|
||||||
<ul class="devlog-list">
|
|
||||||
{% for post in project_posts %}
|
|
||||||
<li class="devlog-item">
|
|
||||||
<a href="/posts/{{ post['slug'] }}" class="devlog-link">{{ render_title(post['title']) }}</a>
|
|
||||||
<span class="devlog-date">{{ local_dt(post['created_at'], 'date') }}</span>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
{% else %}
|
|
||||||
<p class="devlog-empty">No posts yet for this project.</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% with target_uid=project['uid'], target_type="project" %}
|
{% with target_uid=project['uid'], target_type="project" %}
|
||||||
{% include "_comment_section.html" %}
|
{% include "_comment_section.html" %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|||||||
@@ -89,6 +89,53 @@ def test_run_clamps_max_pages_above_cap(app_server):
|
|||||||
_clear_seo_jobs()
|
_clear_seo_jobs()
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_rejects_malformed_scheme(app_server):
|
||||||
|
r = requests.post(
|
||||||
|
f"{BASE_URL}/tools/seo/run",
|
||||||
|
headers=_json_headers(),
|
||||||
|
data={"url": "ahttps://devplace.net/sitem", "mode": "url"},
|
||||||
|
allow_redirects=False,
|
||||||
|
)
|
||||||
|
assert r.status_code in (400, 422), r.text
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_rejects_relative_path(app_server):
|
||||||
|
r = requests.post(
|
||||||
|
f"{BASE_URL}/tools/seo/run",
|
||||||
|
headers=_json_headers(),
|
||||||
|
data={"url": "/feed", "mode": "url"},
|
||||||
|
allow_redirects=False,
|
||||||
|
)
|
||||||
|
assert r.status_code in (400, 422), r.text
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_normalizes_missing_scheme(app_server):
|
||||||
|
try:
|
||||||
|
r = requests.post(
|
||||||
|
f"{BASE_URL}/tools/seo/run",
|
||||||
|
headers=_json_headers(),
|
||||||
|
data={"url": "example.com", "mode": "url", "max_pages": "5"},
|
||||||
|
)
|
||||||
|
assert r.status_code == 200, r.text
|
||||||
|
uid = r.json()["uid"]
|
||||||
|
refresh_snapshot()
|
||||||
|
job = queue.get_job(uid)
|
||||||
|
assert job is not None
|
||||||
|
assert job["payload"]["url"] == "https://example.com"
|
||||||
|
finally:
|
||||||
|
_clear_seo_jobs()
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_rejects_non_http_scheme(app_server):
|
||||||
|
r = requests.post(
|
||||||
|
f"{BASE_URL}/tools/seo/run",
|
||||||
|
headers=_json_headers(),
|
||||||
|
data={"url": "ftp://example.com", "mode": "url"},
|
||||||
|
allow_redirects=False,
|
||||||
|
)
|
||||||
|
assert r.status_code in (400, 422), r.text
|
||||||
|
|
||||||
|
|
||||||
def test_run_enforces_one_active_job_per_owner(app_server):
|
def test_run_enforces_one_active_job_per_owner(app_server):
|
||||||
try:
|
try:
|
||||||
first = requests.post(
|
first = requests.post(
|
||||||
|
|||||||
Reference in New Issue
Block a user