Fix URL across both ends #16
4 changed files with 4 additions and 7 deletions
|
@ -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) {
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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())
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue