From: Andrea Zagli Date: Sun, 24 Sep 2017 19:14:13 +0000 (+0200) Subject: It sounds!!! X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;p=zakjukebox It sounds!!! --- diff --git a/data/zakjukebox/ctpl/template.ctpl b/data/zakjukebox/ctpl/template.ctpl index d3343ac..8142994 100644 --- a/data/zakjukebox/ctpl/template.ctpl +++ b/data/zakjukebox/ctpl/template.ctpl @@ -12,7 +12,7 @@ - + diff --git a/src/index.c b/src/index.c index 7411f28..fd07c73 100644 --- a/src/index.c +++ b/src/index.c @@ -52,7 +52,11 @@ static gchar if (g_file_query_file_type (gfdir, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY) { error = NULL; - gfenum = g_file_enumerate_children (gfdir, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NONE, NULL, &error); + gfenum = g_file_enumerate_children (gfdir, + G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + G_FILE_QUERY_INFO_NONE, + NULL, + &error); if (gfenum == NULL || error != NULL) { @@ -95,11 +99,35 @@ static gchar if (gft == G_FILE_TYPE_DIRECTORY || gft == G_FILE_TYPE_REGULAR) { - g_string_append_printf (ret, - "
  • %s%s%s
  • \n", - gft == G_FILE_TYPE_DIRECTORY ? g_strdup_printf ("", g_file_get_basename (gf)) : "", - g_file_get_basename (gf), - gft == G_FILE_TYPE_DIRECTORY ? "" : ""); + if (gft == G_FILE_TYPE_DIRECTORY) + { + g_string_append_printf (ret, + "
  • %s
  • \n", + g_file_get_basename (gf), + g_file_get_basename (gf)); + } + else + { + const gchar *content_type; + + content_type = g_file_info_get_content_type (gfi); + + if (g_strcmp0 (content_type, "audio/mpeg3") == 0 + || g_strcmp0 (content_type, "audio/mpeg") == 0) + { + g_string_append_printf (ret, + "
  • %s 
  • \n", + g_file_get_basename (gf), + g_file_get_basename (gf), + content_type); + } + else + { + g_string_append_printf (ret, + "
  • %s
  • \n", + g_file_get_basename (gf)); + } + } } } } @@ -229,3 +257,78 @@ index_cd (GMatchInfo *minfo, gpointer user_data) zak_cgi_main_redirect (commons->zcgi_main, "/zakjukebox/index/index"); } + +void +index_audio (GMatchInfo *minfo, gpointer user_data) +{ + g_autofree gchar *file; + g_autofree gchar *pwd; + g_autofree gchar *filename; + + g_autoptr (GError) error; + g_autoptr (GFile) gf; + g_autoptr (GFileInfo) gfi; + + goffset filesize; + + g_autofree gchar *buf; + + Commons *commons = (Commons *)user_data; + g_warning ("AUDIO"); + file = g_match_info_fetch_named (minfo, "file"); + if (file == NULL) + { + return; + } + + pwd = zak_cgi_session_get_value (commons->zcgi_session, "pwd"); + if (pwd == NULL) + { + pwd = g_strdup (""); + } + + filename = g_build_filename (commons->root, pwd, file, NULL); + gf = g_file_new_for_path (filename); + + error = NULL; + gfi = g_file_query_info (gf, + G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SIZE, + G_FILE_QUERY_INFO_NONE, + NULL, + &error); + if (gfi == NULL + || error != NULL) + { + return; + } + + filesize = g_file_info_get_size (gfi); + g_string_printf (commons->header, + "Content-Description: File Transfer\n" + "Content-Type: %s\n" + "Content-Disposition: attachment; filename=\"%s\"\n" + "Content-Transfer-Encoding: binary\n" + "Content-Length: %d\n" + "Expires: 0\n" + "Cache-Control: must-revalidate, post-check=0, pre-check=0\n" + "Pragma: public", + g_file_info_get_content_type (gfi), + file, + filesize); + + error = NULL; + buf = g_malloc0 (filesize); + if (!g_file_load_contents (gf, + NULL, + &buf, + NULL, + NULL, + &error) + || error != NULL) + { + return; + } + + g_string_set_size (commons->out, filesize); + memcpy (commons->out->str, buf, filesize); +} diff --git a/src/index.h b/src/index.h index 8e532f1..901159c 100644 --- a/src/index.h +++ b/src/index.h @@ -29,6 +29,7 @@ void index_index (GMatchInfo *minfo, gpointer user_data); void index_cd (GMatchInfo *minfo, gpointer user_data); +void index_audio (GMatchInfo *minfo, gpointer user_data); #endif /* __INDEX_H__ */ diff --git a/src/main.c b/src/main.c index 2cec1dd..f483a45 100644 --- a/src/main.c +++ b/src/main.c @@ -76,8 +76,9 @@ main (int argc, char *argv[]) zak_cgi_url_connect (zcgi_url, "/", (ZakCgiUrlConnectedFunction)index_index, commons); zak_cgi_url_connect (zcgi_url, "/index[/]?", (ZakCgiUrlConnectedFunction)index_index, commons); zak_cgi_url_connect (zcgi_url, "/index/index", (ZakCgiUrlConnectedFunction)index_index, commons); - zak_cgi_url_connect (zcgi_url, "/index/cd/(?[.a-zA-Z0-9\\-_]+)", (ZakCgiUrlConnectedFunction)index_cd, commons); + zak_cgi_url_connect (zcgi_url, "/index/cd/(?[.a-zA-Z0-9\\-_\\(\\) ]+)", (ZakCgiUrlConnectedFunction)index_cd, commons); zak_cgi_url_connect (zcgi_url, "/index/cd/(?{up})", (ZakCgiUrlConnectedFunction)index_cd, commons); + zak_cgi_url_connect (zcgi_url, "/index/audio/(?[.a-zA-Z0-9\\-_\\(\\) ]+)", (ZakCgiUrlConnectedFunction)index_audio, commons); zak_cgi_url_dispatch (zcgi_url);