Fix URL across both ends #16

Merged
anthony merged 5 commits from fixurl into main 2024-12-25 14:53:21 +00:00
4 changed files with 4 additions and 7 deletions
Showing only changes of commit 4c36f35492 - Show all commits

View file

@ -28,13 +28,11 @@ export default function URLShortener() {
} }
try { try {
const timestamp = Math.floor(Date.now() / 1000);
// Send the POST request to the backend // Send the POST request to the backend
await axios await axios
.post("http://127.0.0.1:8000/api/v1/shorten", { .post("http://127.0.0.1:8000/api/v1/shorten", {
url: url, url: url
timestamp: timestamp,
}) })
.then((response) => { .then((response) => {
if (response) { if (response) {

View file

@ -51,7 +51,7 @@ def main() -> typing.NoReturn:
sys.exit(0) sys.exit(0)
def shorten_it(config: dict, session: Session, data: str, ttl: int): def shorten_it(config: dict, session: Session, data: str, ttl: int = 0):
shortener = Shortener(session, config) shortener = Shortener(session, config)
identifier = shortener.generate_uuid() identifier = shortener.generate_uuid()
if identifier: if identifier:

View file

@ -21,7 +21,7 @@ class Pointer(base.Base):
__tablename__ = "pointers" __tablename__ = "pointers"
id: Mapped[int] = mapped_column(primary_key=True, index=True, init=False) id: Mapped[int] = mapped_column(primary_key=True, index=True, init=False)
data: Mapped[str] = mapped_column(index=True) data: Mapped[str] = mapped_column(index=True)
ttl: Mapped[str] ttl: Mapped[int]
link_id: Mapped[int] = mapped_column(ForeignKey("links.id")) link_id: Mapped[int] = mapped_column(ForeignKey("links.id"))
link: Mapped["Link"] = relationship(back_populates="pointers") link: Mapped["Link"] = relationship(back_populates="pointers")
timestamp: Mapped[datetime] = mapped_column(default=func.now()) timestamp: Mapped[datetime] = mapped_column(default=func.now())

View file

@ -57,7 +57,7 @@ class SiteHandler:
self.shorten_url = shorten_url self.shorten_url = shorten_url
self.lenghten_url = lenghten_url self.lenghten_url = lenghten_url
self.shortenit_load_format = trafaret.Dict( self.shortenit_load_format = trafaret.Dict(
{trafaret.Key("url"): trafaret.URL, trafaret.Key("timestamp"): trafaret.Int} {trafaret.Key("url"): trafaret.URL}
) )
def _get_server_config(self): def _get_server_config(self):
@ -87,7 +87,6 @@ class SiteHandler:
self.configuration.get("Shortener", None), self.configuration.get("Shortener", None),
self.database, self.database,
data["url"], data["url"],
data["timestamp"],
) )
short_url = self._get_url(stub) short_url = self._get_url(stub)
except KeyError as e: except KeyError as e: