Fossil SCM
Add the /jtext webpage, intended for use by XHR.
Commit
5f7fcbabf01abf6fd4b7bc146e709c9d8d0fe9669abff8837aefdc0f7cb87eb9
Parent
c275a166b351d2b…
1 file changed
+57
+57
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -1882,10 +1882,67 @@ | ||
| 1882 | 1882 | } |
| 1883 | 1883 | g.isConst = 1; |
| 1884 | 1884 | deliver_artifact(rid, P("m")); |
| 1885 | 1885 | } |
| 1886 | 1886 | |
| 1887 | + | |
| 1888 | +/* | |
| 1889 | +** WEBPAGE: jtext | |
| 1890 | +** URL: /jtext/HASH?from=N&to=M | |
| 1891 | +** | |
| 1892 | +** Return lines of text from a file as a JSON array - one entry in the | |
| 1893 | +** array for each line of text. | |
| 1894 | +** | |
| 1895 | +** This page is intended to be used in an XHR from javascript on a diff | |
| 1896 | +** page, to return unseen context to fill in additional context when the | |
| 1897 | +** user clicks on the appropriate button. | |
| 1898 | +*/ | |
| 1899 | +void jtext_page(void){ | |
| 1900 | + int rid = 0; | |
| 1901 | + const char *zName = PD("name", ""); | |
| 1902 | + int iFrom = atoi(PD("from","0")); | |
| 1903 | + int iTo = atoi(PD("to","0")); | |
| 1904 | + int ln; | |
| 1905 | + const char *zSep; | |
| 1906 | + Blob content; | |
| 1907 | + Blob line; | |
| 1908 | + Blob *pOut; | |
| 1909 | + | |
| 1910 | + login_check_credentials(); | |
| 1911 | + if( !g.perm.Read ){ login_needed(g.anon.Read); return; } | |
| 1912 | + rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zName); | |
| 1913 | + if( rid==0 ){ | |
| 1914 | + cgi_set_status(404, "Not Found"); | |
| 1915 | + @ Unknown artifact: "%h(zName)" | |
| 1916 | + return; | |
| 1917 | + } | |
| 1918 | + if( iFrom<1 || iTo<iFrom ){ | |
| 1919 | + cgi_set_status(500, "Bad Request"); | |
| 1920 | + @ Invalid line range | |
| 1921 | + return; | |
| 1922 | + } | |
| 1923 | + content_get(rid, &content); | |
| 1924 | + g.isConst = 1; | |
| 1925 | + cgi_set_content_type("text/json"); | |
| 1926 | + ln = 0; | |
| 1927 | + zSep = "[\n"; | |
| 1928 | + while( ln<iFrom ){ | |
| 1929 | + blob_line(&content, &line); | |
| 1930 | + ln++; | |
| 1931 | + } | |
| 1932 | + pOut = cgi_output_blob(); | |
| 1933 | + while( ln<=iTo ){ | |
| 1934 | + blob_append(pOut, zSep, 2); | |
| 1935 | + blob_trim(&line); | |
| 1936 | + blob_append_json_literal(pOut, blob_buffer(&line), blob_size(&line)); | |
| 1937 | + zSep = ",\n"; | |
| 1938 | + blob_line(&content, &line); | |
| 1939 | + ln++; | |
| 1940 | + } | |
| 1941 | + blob_appendf(pOut,"]\n"); | |
| 1942 | + blob_reset(&content); | |
| 1943 | +} | |
| 1887 | 1944 | |
| 1888 | 1945 | /* |
| 1889 | 1946 | ** Generate a verbatim artifact as the result of an HTTP request. |
| 1890 | 1947 | ** If zMime is not NULL, use it as the mimetype. If zMime is |
| 1891 | 1948 | ** NULL, guess at the mimetype based on the filename |
| 1892 | 1949 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1882,10 +1882,67 @@ | |
| 1882 | } |
| 1883 | g.isConst = 1; |
| 1884 | deliver_artifact(rid, P("m")); |
| 1885 | } |
| 1886 | |
| 1887 | |
| 1888 | /* |
| 1889 | ** Generate a verbatim artifact as the result of an HTTP request. |
| 1890 | ** If zMime is not NULL, use it as the mimetype. If zMime is |
| 1891 | ** NULL, guess at the mimetype based on the filename |
| 1892 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1882,10 +1882,67 @@ | |
| 1882 | } |
| 1883 | g.isConst = 1; |
| 1884 | deliver_artifact(rid, P("m")); |
| 1885 | } |
| 1886 | |
| 1887 | |
| 1888 | /* |
| 1889 | ** WEBPAGE: jtext |
| 1890 | ** URL: /jtext/HASH?from=N&to=M |
| 1891 | ** |
| 1892 | ** Return lines of text from a file as a JSON array - one entry in the |
| 1893 | ** array for each line of text. |
| 1894 | ** |
| 1895 | ** This page is intended to be used in an XHR from javascript on a diff |
| 1896 | ** page, to return unseen context to fill in additional context when the |
| 1897 | ** user clicks on the appropriate button. |
| 1898 | */ |
| 1899 | void jtext_page(void){ |
| 1900 | int rid = 0; |
| 1901 | const char *zName = PD("name", ""); |
| 1902 | int iFrom = atoi(PD("from","0")); |
| 1903 | int iTo = atoi(PD("to","0")); |
| 1904 | int ln; |
| 1905 | const char *zSep; |
| 1906 | Blob content; |
| 1907 | Blob line; |
| 1908 | Blob *pOut; |
| 1909 | |
| 1910 | login_check_credentials(); |
| 1911 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1912 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", zName); |
| 1913 | if( rid==0 ){ |
| 1914 | cgi_set_status(404, "Not Found"); |
| 1915 | @ Unknown artifact: "%h(zName)" |
| 1916 | return; |
| 1917 | } |
| 1918 | if( iFrom<1 || iTo<iFrom ){ |
| 1919 | cgi_set_status(500, "Bad Request"); |
| 1920 | @ Invalid line range |
| 1921 | return; |
| 1922 | } |
| 1923 | content_get(rid, &content); |
| 1924 | g.isConst = 1; |
| 1925 | cgi_set_content_type("text/json"); |
| 1926 | ln = 0; |
| 1927 | zSep = "[\n"; |
| 1928 | while( ln<iFrom ){ |
| 1929 | blob_line(&content, &line); |
| 1930 | ln++; |
| 1931 | } |
| 1932 | pOut = cgi_output_blob(); |
| 1933 | while( ln<=iTo ){ |
| 1934 | blob_append(pOut, zSep, 2); |
| 1935 | blob_trim(&line); |
| 1936 | blob_append_json_literal(pOut, blob_buffer(&line), blob_size(&line)); |
| 1937 | zSep = ",\n"; |
| 1938 | blob_line(&content, &line); |
| 1939 | ln++; |
| 1940 | } |
| 1941 | blob_appendf(pOut,"]\n"); |
| 1942 | blob_reset(&content); |
| 1943 | } |
| 1944 | |
| 1945 | /* |
| 1946 | ** Generate a verbatim artifact as the result of an HTTP request. |
| 1947 | ** If zMime is not NULL, use it as the mimetype. If zMime is |
| 1948 | ** NULL, guess at the mimetype based on the filename |
| 1949 |