Change webapp url paths

Don't use `#`, because many people find it awkward. Now "normal" urls
are used and elm takes care to not issue a server request when these
change.
This commit is contained in:
Eike Kettner 2019-12-30 22:28:02 +01:00
parent b15b9cc217
commit 36a6fdd746
5 changed files with 44 additions and 29 deletions

View File

@ -53,7 +53,7 @@ Example screenshot:
This example shows a source with name "test". It defines two urls: This example shows a source with name "test". It defines two urls:
- `/app#/upload/<id>` - `/app/upload/<id>`
- `/api/v1/open/upload/item/<id>` - `/api/v1/open/upload/item/<id>`
The first points to a web page where everyone could upload files into The first points to a web page where everyone could upload files into
@ -66,7 +66,7 @@ files (which is used by the first url).
For example, this url can be used to upload files with curl: For example, this url can be used to upload files with curl:
``` bash ``` bash
$ curl -XPOST -F file=@test.pdf http://localhost:7880/api/v1/open/upload/item/5DxhjkvWf9S-CkWqF3Kr892-WgoCspFWDo7-XBykwCyAUxQ $ curl -XPOST -F file=@test.pdf http://localhost:7880/api/v1/open/upload/item/CqpFTb7UmGe-9nMVPZSmnwc-AHH6nWFh52t-M1JFQ9y7cdH
{"success":true,"message":"Files submitted."} {"success":true,"message":"Files submitted."}
``` ```
@ -126,5 +126,5 @@ uploading two files with meta data:
curl -XPOST -F meta='{"multiple":false, "direction": "outgoing"}' \ curl -XPOST -F meta='{"multiple":false, "direction": "outgoing"}' \
-F file=@letter-en-source.pdf \ -F file=@letter-en-source.pdf \
-F file=@letter-de-source.pdf \ -F file=@letter-de-source.pdf \
http://localhost:7880/api/v1/open/upload/item/5DxhjkvWf9S-CkWqF3Kr892-WgoCspFWDo7-XBykwCyAUxQ http://localhost:7880/api/v1/open/upload/item/CqpFTb7UmGe-9nMVPZSmnwc-AHH6nWFh52t-M1JFQ9y7cdH
``` ```

View File

@ -25,3 +25,7 @@
.docs h4 { .docs h4 {
text-decoration: underline; text-decoration: underline;
} }
.docs .thumbnail img {
width: 100%;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 153 KiB

After

Width:  |  Height:  |  Size: 182 KiB

View File

@ -188,7 +188,7 @@ urlInfoMessage flags model =
] ]
, p [] , p []
[ text "This source defines URLs that can be used by anyone to send files to " [ text "This source defines URLs that can be used by anyone to send files to "
, text "you. There is a web page that you can share or tha API url can be used " , text "you. There is a web page that you can share or the API url can be used "
, text "with other clients." , text "with other clients."
] ]
, dl [ class "ui list" ] , dl [ class "ui list" ]
@ -196,7 +196,7 @@ urlInfoMessage flags model =
, dd [] , dd []
[ let [ let
url = url =
flags.config.baseUrl ++ "/app#/upload/" ++ model.source.id flags.config.baseUrl ++ "/app/upload/" ++ model.source.id
in in
a [ href url, target "_blank" ] [ code [] [ text url ] ] a [ href url, target "_blank" ] [ code [] [ text url ] ]
] ]

View File

@ -139,44 +139,51 @@ pageToString : Page -> String
pageToString page = pageToString page =
case page of case page of
HomePage -> HomePage ->
"#/home" "/app/home"
LoginPage referer -> LoginPage referer ->
Maybe.map (\p -> "/" ++ p) referer Maybe.map (\p -> "/" ++ p) referer
|> Maybe.withDefault "" |> Maybe.withDefault ""
|> (++) "#/login" |> (++) "/app/login"
ManageDataPage -> ManageDataPage ->
"#/manageData" "/app/managedata"
CollectiveSettingPage -> CollectiveSettingPage ->
"#/collectiveSettings" "/app/csettings"
UserSettingPage -> UserSettingPage ->
"#/userSettings" "/app/usettings"
QueuePage -> QueuePage ->
"#/queue" "/app/queue"
RegisterPage -> RegisterPage ->
"#/register" "/app/register"
UploadPage sourceId -> UploadPage sourceId ->
Maybe.map (\id -> "/" ++ id) sourceId Maybe.map (\id -> "/" ++ id) sourceId
|> Maybe.withDefault "" |> Maybe.withDefault ""
|> (++) "#/upload" |> (++) "/app/upload"
NewInvitePage -> NewInvitePage ->
"#/newinvite" "/app/newinvite"
pageFromString : String -> Maybe Page pageFromString : String -> Maybe Page
pageFromString str = pageFromString str =
let let
urlNormed =
if String.startsWith str "http" then
str
else
"http://somehost" ++ str
url = url =
Url.Url Url.Http "" Nothing str Nothing Nothing Url.fromString urlNormed
in in
Parser.parse parser url Maybe.andThen (Parser.parse parser) url
href : Page -> Attribute msg href : Page -> Attribute msg
@ -189,24 +196,28 @@ goto page =
Nav.load (pageToString page) Nav.load (pageToString page)
pathPrefix : String
pathPrefix =
"app"
parser : Parser (Page -> a) a parser : Parser (Page -> a) a
parser = parser =
oneOf oneOf
[ Parser.map HomePage (oneOf [ s "", s "home" ]) [ Parser.map HomePage (oneOf [ Parser.top, s pathPrefix </> s "home" ])
, Parser.map (\s -> LoginPage (Just s)) (s "login" </> string) , Parser.map (\s -> LoginPage (Just s)) (s pathPrefix </> s "login" </> string)
, Parser.map (LoginPage Nothing) (s "login") , Parser.map (LoginPage Nothing) (s pathPrefix </> s "login")
, Parser.map ManageDataPage (s "manageData") , Parser.map ManageDataPage (s pathPrefix </> s "managedata")
, Parser.map CollectiveSettingPage (s "collectiveSettings") , Parser.map CollectiveSettingPage (s pathPrefix </> s "csettings")
, Parser.map UserSettingPage (s "userSettings") , Parser.map UserSettingPage (s pathPrefix </> s "usettings")
, Parser.map QueuePage (s "queue") , Parser.map QueuePage (s pathPrefix </> s "queue")
, Parser.map RegisterPage (s "register") , Parser.map RegisterPage (s pathPrefix </> s "register")
, Parser.map (\s -> UploadPage (Just s)) (s "upload" </> string) , Parser.map (\s -> UploadPage (Just s)) (s pathPrefix </> s "upload" </> string)
, Parser.map (UploadPage Nothing) (s "upload") , Parser.map (UploadPage Nothing) (s pathPrefix </> s "upload")
, Parser.map NewInvitePage (s "newinvite") , Parser.map NewInvitePage (s pathPrefix </> s "newinvite")
] ]
fromUrl : Url -> Maybe Page fromUrl : Url -> Maybe Page
fromUrl url = fromUrl url =
{ url | path = Maybe.withDefault "" url.fragment, fragment = Nothing } Parser.parse parser url
|> Parser.parse parser