|
6 | 6 | from abc import ABC, abstractmethod |
7 | 7 | from enum import Enum |
8 | 8 | from pathlib import Path |
9 | | -from typing import List, Optional, Set, Union |
| 9 | +from typing import Any, List, Optional, Set, Union |
10 | 10 |
|
11 | | -from pydantic import BaseModel, Field |
| 11 | +from pydantic import BaseModel, Field, field_validator |
12 | 12 |
|
13 | 13 | from invokeai.app.services.shared.pagination import PaginatedResults |
14 | 14 | from invokeai.app.services.shared.sqlite.sqlite_common import SQLiteDirection |
@@ -86,6 +86,19 @@ class ModelRecordChanges(BaseModelExcludeNull): |
86 | 86 | source: Optional[str] = Field(description="original source of the model", default=None) |
87 | 87 | source_type: Optional[ModelSourceType] = Field(description="type of model source", default=None) |
88 | 88 | source_api_response: Optional[str] = Field(description="metadata from remote source", default=None) |
| 89 | + source_url: Optional[str] = Field(description="Optional URL for the model (e.g. download page)", default=None) |
| 90 | + |
| 91 | + @field_validator("source_url", mode="before") |
| 92 | + @classmethod |
| 93 | + def validate_source_url(cls, v: Any) -> Optional[str]: |
| 94 | + if v is None or v == "": |
| 95 | + return None |
| 96 | + if not isinstance(v, str): |
| 97 | + raise ValueError("source_url must be a string") |
| 98 | + if not v.startswith(("https://", "http://")): |
| 99 | + raise ValueError("source_url must be an http or https URL") |
| 100 | + return v |
| 101 | + |
89 | 102 | name: Optional[str] = Field(description="Name of the model.", default=None) |
90 | 103 | path: Optional[str] = Field(description="Path to the model.", default=None) |
91 | 104 | description: Optional[str] = Field(description="Model description", default=None) |
|
0 commit comments